Aware IM User Forums Forum Index Aware IM User Forums
Discussions, questions, ideas, opinions about Aware IM
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ORDER BY and TAKE BEST in Where for rule?

 
Post new topic   Reply to topic    Aware IM User Forums Forum Index -> General discussion and questions about Aware IM
View previous topic :: View next topic  
Author Message
nlarson



Joined: 14 Apr 2011
Posts: 393

PostPosted: Mon May 14, 2012 4:33 pm    Post subject: ORDER BY and TAKE BEST in Where for rule? Reply with quote

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
View user's profile Send private message
nlarson



Joined: 14 Apr 2011
Posts: 393

PostPosted: Mon May 14, 2012 7:46 pm    Post subject: Reply with quote

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
View user's profile Send private message
tford



Joined: 10 Mar 2007
Posts: 2600

PostPosted: Mon May 14, 2012 11:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
rocketman



Joined: 02 Jan 2009
Posts: 680
Location: Preston UK

PostPosted: Tue May 15, 2012 1:04 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
nlarson



Joined: 14 Apr 2011
Posts: 393

PostPosted: Thu May 17, 2012 3:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
nlarson



Joined: 14 Apr 2011
Posts: 393

PostPosted: Fri May 18, 2012 1:58 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aware IM User Forums Forum Index -> General discussion and questions about Aware IM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group