Re: Selecting a particular Custom object to display in Velocity Token for emails

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Sandford, 

I'm a little unclear about what you're asking.

Best,
Lucas

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

Please insert code by clicking this button in the toolbar:

 

SanfordWhiteman_0-1682711226574.png

Choose Java as the language.

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

#foreach($data in $cCUAccount_cList)
#if($data.productCode.equals("123"))
${data.nextDueDate}
${data.payment}
${data.productCode}
#end
#end


Like this?

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Re: Selecting a particular Custom object to display in Velocity Token for emails

You should set this up as a daily batch campaign with the "Has <friendly name of custom object> = True" filter, and in the flow, use Send Email flow step.

 

For the email script, you can use the velocity's date tool to find the difference between the current date and the $nextDueDate of all the CO records to check whether it's equal to 7. For the CO records that have the date difference = 7, you can print the CO record details. Additionally, if you wish to add further conditions on the product code along with the date difference equal to 7, you can first add the conditions for the product code. Note that individual product codes should be added in OR condition as you'd need to allow records with any of those product codes. So your code could be something like the below:

 

#set( $defaultTimeZone = $date.getTimeZone().getTimeZone("America/New_York") )
#set( $defaultLocale = $date.getLocale() )
#set( $calNow = $date.getCalendar() )
#set( $ret = $calNow.setTimeZone($defaultTimeZone) )
#set( $calConst = $field.in($calNow) )
#set( $ISO8601DateOnly = "yyyy-MM-dd" )
#set( $ISO8601DateTime = "yyyy-MM-dd'T'HH:mm:ss" )
#set( $ISO8601DateTimeWithSpace = "yyyy-MM-dd HH:mm:ss" )
#set( $ISO8601DateTimeWithMillisUTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" )
#set( $ISO8601DateTimeWithMillisTZ = "yyyy-MM-dd'T'HH:mm:ss.SSSZ" )

#foreach($data in $cCUAccount_cList)
#if($data.productCode.equals("AUTO222") || $data.productCode.equals("AUTO225") || $data.productCode.equals("AUTO2277"))
#if (!$data.nextDueDate.isEmpty() && $data.nextDueDate)
#set( $convertednNextDueDate=$convert.toCalendar(
$convert.parseDate(
$data.nextDueDate, 
$ISO8601DateOnly,
$defaultLocale, 
$defaultTimeZone 
)
))
#set($diffDates=$date.difference($calNow,$convertednNextDueDate))
#set( $differenceInDays= $convert.toInteger($diffDates.getDays()))
#if($differenceInDays == 7)
${data.nextDueDate}
${data.payment}
${data.productCode}
#end 
#end
#end
#end

 

I hope this is helpful. Let us know if you have questions.

 

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Darshil and Sandford,

Okay, the code Darshil provided is a good to know, but it's not really something we are looking to implement into the email itself. I am not sure to which custom token I should be implementing these codes. I really only need the tokens to pull the payment balance and next due date based on their product categories. 

So, for the Payment Custom Token, I have this inserted:

#foreach($data in $cCUAccount_cList)
#if(($data.productCode.equals("PRODUCT 1") || $data.productCode.equals("PRODUCT 2") || $data.productCode.equals("PRODUCT 3") || $data.productCode.equals("PRODUCT 4") || $data.productCode.equals("PRODUCT 5") || $data.productCode.equals("PRODUCT 6") || $data.productCode.equals("PRODUCT 7") || $data.productCode.equals("PRODUCT 8") || $data.productCode.equals("PRODUCT 9") || $data.productCode.equals("PRODUCT 10") || $data.productCode.equals("PRODUCT 11") || $data.productCode.equals("PRODUCT 12") || $data.productCode.equals("PRODUCT 13") || $data.productCode.equals("PRODUCT 14"))
${data.payment}
${data.productCode}
#end
#end

 

Is this the correct code that is being applied? I would assume it is not since upon previewing my email with the custom token applied, an error message was displayed.

Also, since the field for payment is in string format, I am pretty sure it will not be displayed with currency symbols. Can I add coding within here to ensure that it displays the payment amount in currency?

Also, just to confirm, I can use the same coding above with the only change being I would change "data.payment" to "data.next due date" correct?

Lastly, I want to thank you both for your patience. Javascript and Velocity are two areas that I am quite new to and I am trying to learn it as I progress. Thanks again in advance for your continued assistance.

Best,

Lucas

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

Oof. Follow the DRY principle. Itโ€™s more organized, more readable, less prone to typos.

#set( $interestingProductCodes = ["PRODUCT 1","PRODUCT 2","PRODUCT 3"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProductCodes.contains($account.productCode) )
product code is interesting, do or output something
#end
#end

 

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Hi Sandford,

So based on your feedback. I inserted the code with the 14 different product codes accordingly in line as you described below and included an action line under the #if statement.

#set( $interestingProductCodes = ["PRODUCT 1","PRODUCT 2","PRODUCT 3"] )
#foreach( $account in $cCUAccount_cList )
#if( $interestingProductCodes.contains($account.productCode) )
${cCUAccount_cList.get(0).currentPayment}
#end
#end


When I test the custom token in the email it does not appear to be pulling anything. Is there something here that I might have missed?

Best,

Lucas 

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

Canโ€™t make out why youโ€™re doing this.

 

Why would you be always displaying the currentPayment property of the first item in the list, rather than the the current item as youโ€™re iterating?

LCENTENO
Level 3

Re: Selecting a particular Custom object to display in Velocity Token for emails

Basically, I want to display the current payment property of any items that fit the criteria based on their product code. The email is basically informing a customer that opened a new loan that their first payment in the amount of is due on whatever specific date their loan is due:

You're first payment of $0.00 is due on ________.

I am wanting to pull the payment amount based on the product codes that fit that criteria. I hope this makes sense.

 

Best,

Lucas

SanfordWhiteman
Level 10 - Community Moderator

Re: Selecting a particular Custom object to display in Velocity Token for emails

So you should be outputting the properties of $account. Thatโ€™s your loop variable.

 

$account is set to each item in the list, in list order.

 

You should not be referring to the (0)th item in the list. Thatโ€™s the first item.