Re: Printing a paragraph for every condition met

djb
Level 1
Level 1

Printing a paragraph for every condition met

Hi All! New to Maketo and looking into VLT coding but cant seem to get something working.

Is the below possible in VLT code.

 

Person A is is interested in studying Nursing, Marketing and Design

(there are 600 other courses hence why I'm trying to do it in a VS)

 

Instead of sending 3 welcome emails, we would like to send one welcome email but include a paragraph of text about each course.

 

I suspect a a loop or Switch statement would be best, but if anyone has a better way of doing this, please let me know and i will look into it.

 

So the email person A would receive, would look like this:

 

Banner

--------------

Default text

--------------

Nursing text

--------------

Marketing text

--------------

Design text

--------------

Email sign off

 

 

Thanks, Dan

 

11 REPLIES 11
Darshil_Shah1
Level 10 - Community Advisor

Re: Printing a paragraph for every condition met

I think this can be acheived by conditional #if blocks for checking the AOI values for a person to populate the email content. Also, wouldn't the email become too long if person is interested in say like 10 courses? Or, do you have an upper limit for the AOI values (i.e., courses) that a person can have at a time? From what I can understand based on your post is that you've 600 possible AOI values.

 

If required, velocity can also pick a set max. number of AOI values for populating the respective content in the email in-case a person has a lot of AOIs. Ex. pick three AOIs and populate the respective AOI content in the emails in-case the person has like 10 AOI values.

 

Best,
Darshil
SanfordWhiteman
Level 10 - Community Moderator

Re: Printing a paragraph for every condition met


Hi All! New to Maketo and looking into VLT coding but cant seem to get something working.

VTL (Velocity Template Language), not VLT. 🙂

 

 


(there are 600 other courses hence why I'm trying to do it in a VS)

How are these 600 courses stored in Marketo? This is a critical part of the scenario.

 


I suspect a a loop or Switch statement would be best

Velocity doesn't have a switch() per se (in the sense of cases with fallthrough). It has #if/#elseif/#elseif but from your description the cases are all independent. So they may just be a lot of #if/#end conditions. Of course you don't want to repeat content (esp. because there's a max size of the whole token code) so detailed examples are necessary.

 

As @Darshil_Shah1 rightly mentions, you may want to keep track of how many matches you have and set a max # to output.

djb
Level 1
Level 1

Re: Printing a paragraph for every condition met

Ah yes, VTL, apologizes!

 

We have a heavy custom build due to the way data is in MSD, the course data is purely a text field within a Microsoft custom field tab. We have always know about these limitations as we have so many courses and this was deemed the best way to get the data into the system. Obvious segmentation are out of the question with the 100 limit.

 

Each person can only apply for a maximum of 3 courses

 

Data within Marketo looks like this, within the Microsoft custom field tab

 

Trying to work it out but I think the #if/#end is the best way to go, trouble will be if i hit the token max size which is 100kb i believe. Is there anywhere where it states how big the script size is?

 

Thanks for your reply!

SanfordWhiteman
Level 10 - Community Moderator

Re: Printing a paragraph for every condition met


Trying to work it out but I think the #if/#end is the best way to go, trouble will be if i hit the token max size which is 100kb i believe. Is there anywhere where it states how big the script size is?


Do you mean how many bytes your code takes up as you type? No, you'd have to do the math yourself.

 

Like I said the question is going to be how different each block is. If you have 600 text blocks with absolutely nothing in common, then you'd be limited to about 150 bytes for each (leaving room for the logic itself). That's pretty darn short. But you'd have to tell us what you're planning to output.

 

Jo_Pitts1
Level 10 - Community Advisor

Re: Printing a paragraph for every condition met

What about this:

  • Create a text token for each paragraph text.  Name them meaningfully (intro_text_nursing, intro_text_marketing etc.)
  • Create a velocity token that:
    • has a map from each course to the text token name
    • loops through the courses of interest, checks in the map, retrieves the text token, and outputs it

Cheers

Jo

djb
Level 1
Level 1

Re: Printing a paragraph for every condition met

I like this idea, but i didn't think it was possible to pull a text token into a email script, or is text tokens put somewhere else?

djb
Level 1
Level 1

Re: Printing a paragraph for every condition met

It would just be a paragraph with course highlights and entry requirements. Sorry in at the deep end here and learning as i go, so sorry if the below is looking bad. Seems our custom tokens are also not printing correctly.... so that is also messing things up.

 

#set( $course = $ccl1000_coursesubjectinterestList.get(0).uod_marketosubjectarea)

#set( $subjectarea = [
{
"text" : ["Nursing"],
 "bio" : "Nursing text goes here"
},
{
 "text" : ["Marketing"],
 "bio" : "Marketing text goes here"
},
{
 "text" : ["PE"],
 "bio" : "PE text goes here"
},
{
 "text" : ["Arts"],
 "bio" : "Arts text goes here"
},
{
 "text" : ["Accounting"],
 "bio" : "accounting text goes here"
}
] )
#set( $defaultsubjectarea = {
 "Bio" : "default text goes here"
} )
##
#foreach( $matchable in $subjectarea )
#if( $matchable.text.contains($course) )
#set( $subject = $matchable )
#break
#end
#end
#set( $subject = $display.alt($subject,$defaultsubjectarea) )
course 1: ${subject.bio}



Jo_Pitts1
Level 10 - Community Advisor

Re: Printing a paragraph for every condition met

@djb ,

OK.  So, the approach to take here is to:

  • create a map with your data.
  • iterate through your list of courses, and for each one, output a paragraph from the map

Something a bit like this:

## This part sets up all your course data
#set( $allCourseDetails = {
  "Nursing" : {
    "bio":"Some text about the nursing course"
  },
  "Poker" : {
    "bio":"a course on how to lose less money at poker"
  },
  "Like a Boss" : {
    "bio":"How to be like a boss"
  }
}
)

## This loops through your custom objects that contains the courses of interest
#foreach( $aInterest in $ccl1000_coursesubjectinterestList )
  ## This finds the course from the current CO in the map, and puts it into aCourse
  #set( $aCourse = $allCourseDetails[$aInterest.uod_marketosubjectarea].bio)
  ## This outputs the bio details.  You'll want to add formatting here.
  ${aCourse.Bio}
  ## if you had more details (i.e. course start dates, you could add them in here
  ## and into the map above
#end

 

make sure you've got all the requisite fields checked off in the Velocity editor.

 

Some of your code implies you're wanting a default bio to be displayed if they have no courses of interest?  If that's the case, let me know and we can extend the above.

 

Cheers

Jo

SanfordWhiteman
Level 10 - Community Moderator

Re: Printing a paragraph for every condition met

This line seems very questionable:

#set( $course = $ccl1000_coursesubjectinterestList.get(0).uod_marketosubjectarea)

You almost never want to go directly to the first item in a list without sorting the list first. Assume all CO lists are unsorted.

 

An explanation of how your COs and their fields are populated would be useful.