SOLVED

Re: How to find if a boolean field is true on the latest Opportunity

Go to solution
ivvvan
Level 1

How to find if a boolean field is true on the latest Opportunity

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.

2 ACCEPTED SOLUTIONS

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: How to find if a boolean field is true on the latest Opportunity

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.

View solution in original post

SanfordWhiteman
Level 10 - Community Moderator

Re: How to find if a boolean field is true on the latest Opportunity

Your dump of the list shows the name of the field is

 

  Marketo Created At

 

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: How to find if a boolean field is true on the latest Opportunity

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.

ivvvan
Level 1

Re: How to find if a boolean field is true on the latest Opportunity

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}

 

SanfordWhiteman
Level 10 - Community Moderator

Re: How to find if a boolean field is true on the latest Opportunity

You're sorting on createdAt but you haven't selected a field of that name in the tree in Script Editor.

ivvvan
Level 1

Re: How to find if a boolean field is true on the latest Opportunity

I've selected 'Created At' under the Opportunity in the tree. 

Is this the correct field, or am I missing something else? 

Screen Shot 2021-01-20 at 1.47.08 PM.png

SanfordWhiteman
Level 10 - Community Moderator

Re: How to find if a boolean field is true on the latest Opportunity

Your dump of the list shows the name of the field is

 

  Marketo Created At

 

ivvvan
Level 1

Re: How to find if a boolean field is true on the latest Opportunity

Thank you so much!