SOLVED

Re: Set order with velocity

Go to solution
Kainelson
Level 2

Set orders with velocity

I am looking to write up some velocity script for a new project. We want to send out dynamic emails to our partners that have outstanding onboarding tasks to complete. We want them to receive an email every few days that will list 3 (or less depending on how many tasks they have left to do) tasks that they haven't completed and link them to the dashboard where they can finish them.  I was thinking that in velocity I would set an order to the 8 tasks (these will be boolean fields marked true or false depending on completion) and have it display the ones that are not complete in the email, but I'm not sure how to cap it 3 tasks. Also, want to make sure that by setting an "order" to the tasks, it will show the most important tasks to list first (hope that makes sense). For example, if they have 5 tasks left to do, I only want to display 3 of the most important ones in the email. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Set order with velocity

Custom Objects are always many-to-one.  So while your implementation may ensure there’s only zero or one CO record for each Marketo person, it’s still always a list of COs in Marketo.

 

So you set the display order ($TaskPriority is an ordered list) and the max to display.

 

Then loop over the list of COs. For each CO record, you loop over $TaskPriority and see whether the field with the same name was set to Boolean true (String "1" in Velocity). Depending on the value, add it to the list of complete/incomplete tasks.

 

Finally, loop over the incomplete tasks, limiting to a max # of items using common logic.

 

## order
#set( $TaskPriority = [
  "Apple_Task",
  "Orange_Task",
  "Pear_Task",
  "Banana_Task"
] )
## max to show in email
#set( $showMax = 3 )
##
#if( !$Object_cList.isEmpty() )
  #foreach( $object in $Object_cList )
    ## filter matching tasks into new list
    #set( $completeTasks = [] )
    #set( $incompleteTasks = [] )
    #foreach( $task in $TaskPriority )
      #if( $object[$task].equals("1") )
        #set( $void = $completeTasks.add($task) )
      #else
        #set( $void = $incompleteTasks.add($task) )
      #end
    #end
    ## decide items to show
    #set( $showEffective = $math.min($incompleteTasks.size(), $showMax) )
    #set( $showableIncompleteTasks = $incompleteTasks.subList(0, $showEffective) )
    ## iterate displayables
    #foreach( $task in $showableIncompleteTasks )
      ${task} is incomplete
    #end
  #end
#end

 

 

 

 

View solution in original post

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: Set order with velocity

It’s helpful if you show the actual “shape” of your data so we’re not discussing things too abstractly.

 

Are you talking about a Custom Object list? Do you want to sort the list by a Date or DateTime field that’s present on each record? Please be as detailed as possible.

Kainelson
Level 2

Re: Set order with velocity

So here are the tasks they need to complete during onboarding: 

Policies & Settings (1)

Property/Amenties submitted (2)

Rooms & Rates (3)

Photos submitted (4)

Tax Information (5)

Property Overview (6)

Pre Live (7)

 

We will have our data engineering sending this data through to a custom object in boolean fields (true=completed, false=incomplete). Partner can complete these tasks out of order. So for example, they could have submitted photos, but have not completed tax info, rooms and rates, property amenities, property overview, and pre live.. in their email we want to show only 3 tasks that they still need to complete but we only want the 3 highest "ranked" by the order I set. So, according to the order I have made above, I would like them to see that the next tasks to complete are: 

Property amenities 

Room & Rates 

Tax information

 

We will have a date/time field that will be updated everytime data is sent through for these fields that will be a "last updated at" dat/time field. Every field will be updated at the same time so I think just one updated field is necessary. That is not what we will use to sort though. 

 

Does that help?

SanfordWhiteman
Level 10 - Community Moderator

Re: Set order with velocity

OK. I’m going to put the solution on the Products blog so more people can learn from it. I assume the Task name is stored in a String field like name.

 

 

Kainelson
Level 2

Re: Set order with velocity

It will be in boolean fields with the task name. Example: CL Property Amenities 

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Set order with velocity

Please show the exact definition of your Custom Object and a sample list of Custom Objects with field values.

 

It’s not possible to answer this without an actual look at your data. Right now, it doesn’t seem like you’ve chosen the proper architecture: if every CO record corresponds to a single Task, it should have a single field identifying the Task name. And if a single CO record corresponds to multiple Tasks... why?

Kainelson
Level 2

Re: Set order with velocity

I think I might be confused. We will have a custom object (hasn't been created yet) named Onboarding Interaction. Within that, there will be boolean fields listed like: 

 

- Contract Received / Signed  (true/false)

- Policies & Settings submitted (true/false)

- Property Amenities submitted (true/false)

- Rooms & Rates submitted (true/false)

- Photos submitted (true/false)

- Taxes information submitted (true/false)

 

Does that make sense?

SanfordWhiteman
Level 10 - Community Moderator

Re: Set order with velocity

Custom Objects are always many-to-one.  So while your implementation may ensure there’s only zero or one CO record for each Marketo person, it’s still always a list of COs in Marketo.

 

So you set the display order ($TaskPriority is an ordered list) and the max to display.

 

Then loop over the list of COs. For each CO record, you loop over $TaskPriority and see whether the field with the same name was set to Boolean true (String "1" in Velocity). Depending on the value, add it to the list of complete/incomplete tasks.

 

Finally, loop over the incomplete tasks, limiting to a max # of items using common logic.

 

## order
#set( $TaskPriority = [
  "Apple_Task",
  "Orange_Task",
  "Pear_Task",
  "Banana_Task"
] )
## max to show in email
#set( $showMax = 3 )
##
#if( !$Object_cList.isEmpty() )
  #foreach( $object in $Object_cList )
    ## filter matching tasks into new list
    #set( $completeTasks = [] )
    #set( $incompleteTasks = [] )
    #foreach( $task in $TaskPriority )
      #if( $object[$task].equals("1") )
        #set( $void = $completeTasks.add($task) )
      #else
        #set( $void = $incompleteTasks.add($task) )
      #end
    #end
    ## decide items to show
    #set( $showEffective = $math.min($incompleteTasks.size(), $showMax) )
    #set( $showableIncompleteTasks = $incompleteTasks.subList(0, $showEffective) )
    ## iterate displayables
    #foreach( $task in $showableIncompleteTasks )
      ${task} is incomplete
    #end
  #end
#end