Custom Objects Data to display in email | Community
Skip to main content
Level 5
May 1, 2020
Solved

Custom Objects Data to display in email

  • May 1, 2020
  • 1 reply
  • 3376 views

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by SanfordWhiteman

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.


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.

1 reply

SanfordWhiteman
Level 10
May 1, 2020

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.

Level 5
May 1, 2020

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
May 1, 2020

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