| View previous topic :: View next topic |
| Author |
Message |
nlarson
Joined: 14 Apr 2011 Posts: 393
|
Posted: Mon May 14, 2012 4:33 pm Post subject: ORDER BY and TAKE BEST in Where for rule? |
|
|
It seems like adding “ORDER BY bo.attribute DESC' and 'TAKE BEST 1” are incompatible with BO rules when a WHERE is present. I was wondering if that is by design?
Below is the real way I was trying to use it. Was hoping to avoid moving this into a process with a very complex THIS and THAT logic by using AVG of a single result as the value used to update a reference e object.
Measurements.MetricsReference.LastMeasureDate= AVG Measurements.DueBy WHERE (Measurements.MetricsReference=ThisMeasurements.MetricsReference AND Measurements.Confidence IS DEFINED ORDER BY Measurements.DueBy DESC TAKE BEST 1)
I tried a few ways to tackle this, and was hoping that it's maybe just a syntax error? |
|
| Back to top |
|
 |
nlarson
Joined: 14 Apr 2011 Posts: 393
|
Posted: Mon May 14, 2012 7:46 pm Post subject: |
|
|
So to provide some more info on this. I have a Parent BO Instance (Metrics), when it is created 12 Child BO Instances (Measurements)are creating as place holders for monthly data entry. I have a rule which updates a date field in the parent when conditions are matched in the child: it fires this action:
Measurements.MetricsReference.LastMeasureDate=ThisMeasurements.DueBy
In a vacuum this works fine, as the user fills in data over the year the measurement date progresses towards the end. However… in real life this method can be problematic since occasionally, a user goes ‘back’ to revise some older info: when that happens the LastMeasureDate (and it’s subsequent calculations) are thrown out of whack. The current work around is to ask users to then go and make a change to the correct Measurement to fix the date. Obviously that is cumbersome so what I would like to do is create a rule or process which selects ‘the right’ Child.
Ideally I will trigger a rule/process which will find the child BO instance with a date closest to, but not greater than current_date. That item would be used to form that context and thus provide the value to update the parent reference attribute. I was thinking could use a rule like the one below to ‘trick’ the system into picking the correct value
Measurements.MetricsReference.LastMeasureDate= AVG Measurements.DueBy WHERE (Measurements.MetricsReference=ThisMeasurements.MetricsReference AND Measurements.Confidence IS DEFINED ORDER BY Measurements.DueBy DESC TAKE BEST 1)
However, per my original post that did not work. So I then tried 2 processes, but I could not resolve the value using This or That. Here is one flavor of the process called from the parent:
FIND Measurements WHERE Measurements.MetricsReference=ThisMetrics AND Measurements.Confidence IS DEFINED ORDER BY Measurements.DueBy DESC TAKE BEST 1
Metrics.LastMeasureDate=ThatMeasurements.DueBy
I tried a few variants and some this/that combos to no avail. I am about to split the process into two process to see if that works, but I feel like I might be trying to swat a fly with a sledge hammer, so if anyone has some ideas ot other approaches on how to tackle this I am all ears. |
|
| Back to top |
|
 |
tford
Joined: 10 Mar 2007 Posts: 2600
|
Posted: Mon May 14, 2012 11:14 pm Post subject: |
|
|
| Quote: | FIND Measurements WHERE Measurements.MetricsReference=ThisMetrics AND Measurements.Confidence IS DEFINED ORDER BY Measurements.DueBy DESC TAKE BEST 1
Metrics.LastMeasureDate=ThatMeasurements.DueBy |
Have you tried it without THIS and THAT prefixes? _________________ Tom (running V5.6 - build 1654 - on Windows)
LinkedIn: http://www.linkedin.com/in/itomford |
|
| Back to top |
|
 |
rocketman
Joined: 02 Jan 2009 Posts: 680 Location: Preston UK
|
Posted: Tue May 15, 2012 1:04 pm Post subject: |
|
|
Hows about
FIND Measurements WHERE (Measurements IN Metrics.whatever the ref field is called AND Measurements.Confidence IS DEFINED) ORDER BY Measurements.DueBy DESC TAKE BEST 1 _________________ Rocketman
V5.6 Build 1654 Developer Edition. Server 2008 web edition |
|
| Back to top |
|
 |
nlarson
Joined: 14 Apr 2011 Posts: 393
|
Posted: Thu May 17, 2012 3:31 pm Post subject: |
|
|
| Thanks guys, I will give these a try today! If this does not work then I have worked out a petty solid alternate approach. It's not quite prefect but an 90% improvement. |
|
| Back to top |
|
 |
nlarson
Joined: 14 Apr 2011 Posts: 393
|
Posted: Fri May 18, 2012 1:58 pm Post subject: |
|
|
| Yep, turns out that sledge hammer is no good for swatting flies... removing the This/That got this working as desired. Thank you so much guys! |
|
| Back to top |
|
 |
|