SOLVED

Re: Custom Objects Data to display in email

Go to solution
Jay00031987
Level 4

Custom Objects Data to display in email

in email, I am using  my token as a email script to display custom objects data but when displaying data in email it display data for old value as well as new value I want to refrain the old data and want to display only new data in email.

Jay
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Objects Data to display in email

Then the modification to the code from your other thread is:

 

## constants/strings
#set( $DEFAULT_OUTPUT_NO_LIST = "No records in list." )
#set( $DEFAULT_OUTPUT_NO_PROPERTY = 0 )
## loop, paying attn to emptiness and null-ness
#if( $someObjectList.isEmpty() )
#set( $outputBuilder = $DEFAULT_OUTPUT_NO_LIST )
#else
#foreach( $someObjectName in $sorter.sort($someObjectList, "someDateProperty:desc") )
#if( !$display.alt($someObjectName["somePropertyName"],"").isEmpty() )
#set( $outputBuilder = $someObjectName["somePropertyName"] )
#break
#end
#end
#set( $outputBuilder = $display.alt($outputBuilder, $DEFAULT_OUTPUT_NO_PROPERTY) )
#end
${outputBuilder}

 

The list is sorted by the DateTime field in descending order. When a match is found then you #break out of the #foreach so the output is not overwritten. This is a crucial pattern to understand in Velocity. There's no formal way to filter a list, you loop-until-break. 

 

You'll need to insert the actual field names from your instance of course, this is a framework with generic property names. someDateProperty would be replaced with your DateTime field. Keep the :desc as that means descending order.

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Objects Data to display in email

What constitutes "old" records?

 

Be exact: Field names. Field datatypes. Comparisons.

 

Though you were doing better toward the end of your other thread, you're being unclear again. I ask that you respect that you're getting pro bono help from experts here. Spend more of your time on the details as we spend our own time helping you.

Jay00031987
Level 4

Re: Custom Objects Data to display in email

Hi San,

I know your time is precious and really appreciate your hard work.

 

field name - totalitem

Field type - integer

Comparison- if day-1 item purchased is 5 it will add to CO 5 and in day-2 item purchased 3 it will add to CO 3 so when day-2 email is sent totalitem should display 3 only not both data 5 3.

 

Jay
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Objects Data to display in email

There has to be a Date or DateTime field, or there's nothing to sort on.

Jay00031987
Level 4

Re: Custom Objects Data to display in email

Yes!

Date created and Date updated is also being mapped in the CO list. with data type datetime.

Hence, date updated can be used to sort it out.

Jay
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Objects Data to display in email

Then the modification to the code from your other thread is:

 

## constants/strings
#set( $DEFAULT_OUTPUT_NO_LIST = "No records in list." )
#set( $DEFAULT_OUTPUT_NO_PROPERTY = 0 )
## loop, paying attn to emptiness and null-ness
#if( $someObjectList.isEmpty() )
#set( $outputBuilder = $DEFAULT_OUTPUT_NO_LIST )
#else
#foreach( $someObjectName in $sorter.sort($someObjectList, "someDateProperty:desc") )
#if( !$display.alt($someObjectName["somePropertyName"],"").isEmpty() )
#set( $outputBuilder = $someObjectName["somePropertyName"] )
#break
#end
#end
#set( $outputBuilder = $display.alt($outputBuilder, $DEFAULT_OUTPUT_NO_PROPERTY) )
#end
${outputBuilder}

 

The list is sorted by the DateTime field in descending order. When a match is found then you #break out of the #foreach so the output is not overwritten. This is a crucial pattern to understand in Velocity. There's no formal way to filter a list, you loop-until-break. 

 

You'll need to insert the actual field names from your instance of course, this is a framework with generic property names. someDateProperty would be replaced with your DateTime field. Keep the :desc as that means descending order.

Jay00031987
Level 4

Re: Custom Objects Data to display in email

Thanks San!

Once again, I want really appreciate your hard work!!!🙂 

 

 

Jay