Forums
Extending Daylite
Scripting
Selecting Highest cachedTotalAmount Value - Qualifier?|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Apprentice |
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 |
||
|
|
Apprentice |
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 |
|||
|
|
Marketcircle Team |
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 |
|||
|
|
Apprentice |
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 |
|||
|
|
Marketcircle Team |
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. |
|||
|
|
Marketcircle Team |
Open up Console before running this script and you'll see the highest cachedTotalAmount and the name of the opportunity.
|
|||
|
|
Apprentice |
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 |
|||
|
|
Marketcircle Team |
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, |
|||
|
|
Apprentice |
Thanks, this solved my problem Oscar.
Francesco |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|
Forums
Extending Daylite
Scripting
Selecting Highest cachedTotalAmount Value - Qualifier?
