Hi there,
I am having trouble finding a solution for my email script. Here I am trying to find if a boolean field is true or false on a customer's latest opportunity.
Depending on the result, I would like to display different text.
This is the code I am using:
#set( $sortedList = $sorter.sort( $OpportunityList,["createdAt:desc"]) )
#if ($sortedList.get(0).HP_Payment_Protect__c)
True, you have Payment Protect
#else
False, you do not have Payment Protect.
#end
Please, and thank you.
Solved! Go to Solution.
If it's truly a Boolean field then use
#if( $sortedList[0].HP_Payment_Protect__c.equals(true) )
Don't rely on truthy and falsy coercion. It will lead to unexpected behavior. Use explicit comparison to the expected values.
Your dump of the list shows the name of the field is
Marketo Created At
If it's truly a Boolean field then use
#if( $sortedList[0].HP_Payment_Protect__c.equals(true) )
Don't rely on truthy and falsy coercion. It will lead to unexpected behavior. Use explicit comparison to the expected values.
Thanks Sanford!
I'm now having an issue with sorting. I'm using..
#set( $sortedList = $sorter.sort( $OpportunityList,["createdAt:desc"]) )
but it keeps returning the first Opportunity (null).
{HP_Payment_Protect__c=null, MarketoCreatedAt=2017-02-20 23:03:50}
{HP_Payment_Protect__c=null, MarketoCreatedAt=2017-02-20 23:17:48}
{HP_Payment_Protect__c=1, MarketoCreatedAt=2017-02-20 23:25:11}
{HP_Payment_Protect__c=null, MarketoCreatedAt=2017-09-27 03:22:52}
{HP_Payment_Protect__c=0, MarketoCreatedAt=2017-09-27 19:08:46}
{HP_Payment_Protect__c=null, MarketoCreatedAt=2018-10-25 00:56:11}
{HP_Payment_Protect__c=null, MarketoCreatedAt=2018-12-14 14:10:35}
{HP_Payment_Protect__c=null, MarketoCreatedAt=2018-12-14 14:48:17}
{HP_Payment_Protect__c=1, MarketoCreatedAt=2018-12-14 15:09:51}
{HP_Payment_Protect__c=1, MarketoCreatedAt=2019-09-05 03:23:26}
You're sorting on createdAt but you haven't selected a field of that name in the tree in Script Editor.
I've selected 'Created At' under the Opportunity in the tree.
Is this the correct field, or am I missing something else?
Thank you so much!