Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    Selecting Highest cachedTotalAmount Value - Qualifier?
Go
New
Find
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
Apprentice
Posted
Hi All,

Trying to pull out some data regarding Opportunity with Highest cachedTotalAmount, is there a qualifier that can do this?

qual3 := BDKeyValueQualifier keyValueQualifierWithKey:'cachedTotalAmount' operatorSelector:# ????

Thanks for your help.


Francesco
 
Posts: 7 | Registered: June 19, 2007Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
I came up with this:

highest := (element valueForKeyPath:'parent.reportData.object.@max.cachedTotalAmount')

qual3 := BDKeyValueQualifier keyValueQualifierWithKey:'cachedTotalAmount' operatorSelector:#isEqualTo: value:highest.

But it's returning no data...

Any suggestions?


Francesco
 
Posts: 7 | Registered: June 19, 2007Reply With QuoteEdit or Delete MessageReport This Post
AJ
Marketcircle Team
Picture of AJ
Posted Hide Post
That could work, but you need to apply the qualifier to the array. You would need something like:

all_opps := element valueForKeyPath:'objects'.
opps := all_opps filteredArrayUsingQualifier:qual3.

the_opp := opps lastObject.

the_opp.


A quick explanation:
element valueForKeyPath:'objects'

Will get the opportunities from a parent element that has 'objects'.


There is another way to do this as well. Instead of filtering, you can sort by the total ammount and grab the last.

sort := (((NSSortDescriptor alloc) initWithKey:'cachedTotalAmount' ascending:true) autorelease).
opps := element valueForKeyPath:'objects'.
sorted := opps sortedArrayUsingDescriptors:{sort}.

the_opp := sorted lastObject.

the_opp.


Either technique will work - it's a really case of what you prefer (coding wise).

HTH
 
Posts: 890 | Location: Toronto | Registered: May 03, 2006Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
Thanks AJ

I was trying to use the sorting option but unfortunately it isn't working for me.

can you expand on that please?

here is the code:

start := (element valueForKeyPath:'userInput.startDate') dateAsBeginningOfDay.
end := (element valueForKeyPath:'userInput.endDate') dateAsEndOfDay.

qual1 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isGreaterThan: value:start.
qual2 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isLessThan: value:end.
qual3 := BDQualifier qualifierWhereValueOfKey:'category.name' isLike:'Duplicate'.
notQual := (((BDNotQualifier alloc) initWithQualifier:qual3) autorelease).

qualifiers := {qual1, qual2, notQual}.

andQual := (((BDAndQualifier alloc) initWithQualifierArray:qualifiers) autorelease).

sort := (((NSSortDescriptor alloc) initWithKey:'cachedTotalAmount' ascending:true) autorelease).
opps := element valueForKeyPath:'objects'.
sorted := opps sortedArrayUsingDescriptors:{sort}.

the_opp := sorted lastObject.

the_opp.

objectContext objectsForEntityNamed:'Opportunity' matchingQualifier:andQual.

-----------------

This is returning no data...

Any ideas?


Francesco
 
Posts: 7 | Registered: June 19, 2007Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Oscar
Posted Hide Post
What do you want to do with the highest cachedTotalAmount?

Try this:

start := (element valueForKeyPath:'userInput.startDate') dateAsBeginningOfDay.
end := (element valueForKeyPath:'userInput.endDate') dateAsEndOfDay.

qual1 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isGreaterThan: value:start.
qual2 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isLessThan: value:end.
qual3 := BDQualifier qualifierWhereValueOfKey:'category.name' isLike:'Duplicate'.
notQual := (((BDNotQualifier alloc) initWithQualifier:qual3) autorelease).

qualifiers := {qual1, qual2, notQual}.

andQual := (((BDAndQualifier alloc) initWithQualifierArray:qualifiers) autorelease).


sort := (((NSSortDescriptor alloc) initWithKey:'cachedTotalAmount' ascending:true) autorelease).
opps := objectContext objectsForEntityNamed:'Opportunity' matchingQualifier:andQual.
sorted := opps sortedArrayUsingDescriptors:{sort}.
theOpp := sorted lastObject.

oppName := theOpp valueForKeyPath:'name'.
oppCachedTotalAmount := theOpp valueForKeyPath:'cachedTotalAmount'.
sys log: oppName.
sys log: oppCachedTotalAmount.


objectContext objectsForEntityNamed:'Opportunity' matchingQualifier:andQual.
 
Posts: 505 | Location: Toronto | Registered: February 20, 2007Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Oscar
Posted Hide Post
Open up Console before running this script and you'll see the highest cachedTotalAmount and the name of the opportunity.
 
Posts: 505 | Location: Toronto | Registered: February 20, 2007Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
quote:
Originally posted by Oscar:
What do you want to do with the highest cachedTotalAmount?


Hi oscar, thank you for your imput. What I need to do is to filter opp in a table and display them in the data row, but instead of displaying all records as filter, I was to display only the opp with the highest cachedTotalAmount.

Hope this makes it clear.

So far, despite yours and AJ's effort, I have not been able to even sort them by cachedTotalAmount...

Any more help is appreciated...

Thanks again.


Francesco
 
Posts: 7 | Registered: June 19, 2007Reply With QuoteEdit or Delete MessageReport This Post
Marketcircle Team
Picture of Oscar
Posted Hide Post
quote:
Originally posted by Francesco Liguori:
quote:
Originally posted by Oscar:
What do you want to do with the highest cachedTotalAmount?


Hi oscar, thank you for your imput. What I need to do is to filter opp in a table and display them in the data row, but instead of displaying all records as filter, I was to display only the opp with the highest cachedTotalAmount.

Hope this makes it clear.

So far, despite yours and AJ's effort, I have not been able to even sort them by cachedTotalAmount...

Any more help is appreciated...

Thanks again.




Well that clears up things. I was trying to figure out what you were doing based on the last script you posted in which the table and highest total cached amount looked as if they weren't related.


------------------------------------------------------------

"The following script is for a table. It will sort the opportunities by cachedTotalAmount."



start := (element valueForKeyPath:'userInput.startDate') dateAsBeginningOfDay.
end := (element valueForKeyPath:'userInput.endDate') dateAsEndOfDay.

qual1 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isGreaterThan: value:start.
qual2 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isLessThan: value:end.
qual3 := BDQualifier qualifierWhereValueOfKey:'category.name' isLike:'Duplicate'.
notQual := (((BDNotQualifier alloc) initWithQualifier:qual3) autorelease).

qualifiers := {qual1, qual2, notQual}.

andQual := (((BDAndQualifier alloc) initWithQualifierArray:qualifiers) autorelease).


sort := (((NSSortDescriptor alloc) initWithKey:'cachedTotalAmount' ascending:true) autorelease).
opps := objectContext objectsForEntityNamed:'Opportunity' matchingQualifier:andQual.
sorted := opps sortedArrayUsingDescriptors:{sort}.
sorted.

------------------------------------------------------------

"The following script it for a a dynamic text box. You do not use tables for this because it does not bring back multiple objects to list. It Brings back the highest cached total amount."


start := (element valueForKeyPath:'userInput.startDate') dateAsBeginningOfDay.
end := (element valueForKeyPath:'userInput.endDate') dateAsEndOfDay.

qual1 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isGreaterThan: value:start.
qual2 := BDKeyValueQualifier keyValueQualifierWithKey:'createDate' operatorSelector:#isLessThan: value:end.
qual3 := BDQualifier qualifierWhereValueOfKey:'category.name' isLike:'Duplicate'.
notQual := (((BDNotQualifier alloc) initWithQualifier:qual3) autorelease).

qualifiers := {qual1, qual2, notQual}.

andQual := (((BDAndQualifier alloc) initWithQualifierArray:qualifiers) autorelease).


sort := (((NSSortDescriptor alloc) initWithKey:'cachedTotalAmount' ascending:true) autorelease).
opps := objectContext objectsForEntityNamed:'Opportunity' matchingQualifier:andQual.
sorted := opps sortedArrayUsingDescriptors:{sort}.
theOpp := sorted lastObject.

oppCachedTotalAmount := theOpp valueForKeyPath:'cachedTotalAmount'.

oppCachedTotalAmount.

This message has been edited. Last edited by: Oscar,
 
Posts: 505 | Location: Toronto | Registered: February 20, 2007Reply With QuoteEdit or Delete MessageReport This Post
Apprentice
Posted Hide Post
Thanks, this solved my problem Oscar.


Francesco
 
Posts: 7 | Registered: June 19, 2007Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

Marketcircle    Forums  Hop To Forum Categories  Extending Daylite  Hop To Forums  Scripting    Selecting Highest cachedTotalAmount Value - Qualifier?

© Copyright 2006 Marketcircle Inc. All rights reserved.