$TriggerObject usage according to documentation

Mark_Westerman
Level 2

Re: $TriggerObject usage according to documentation

This sounds interesting. How is this done?

What is a Velocity token?

Is there a separate Velocity token for each product?

Can this information be imported or does it have to keyed in directly?

SanfordWhiteman
Level 10 - Community Moderator

Re: $TriggerObject usage according to documentation

What is a Velocity token?

"Email Script" tokens are written in Apache Velocity Template Language (VTL).

Is there a separate Velocity token for each product?

No, one token. That token defines one $variable (an ArrayList) that holds the product catalog.

Can this information be imported or does it have to keyed in directly?

You can use the API to write the token if you want.

Mark_Westerman
Level 2

Re: $TriggerObject usage according to documentation

I have hacked some code that you have posted in a different discussion but it is returning the default value rather than the value that matches the CourseCode on the Lead. Am I on the right track? I know this code originally related to a custom object. This is the code I am using and I expected to match on 5522US.

## Set up your map of Courses to related asset(s) 

#set( $assetsByCourse = { 

  "5522US" : { 

    "OCBURL" : "http://www.csu.edu.au/courses/bachelor-of-science-honours

  }, 

  "1105PP" : { 

    "OCBURL" : "http://www.police.nsw.gov.au/recruitment/home

  }, 

  "" : { 

    "OCBURL" : "http://www.csu.edu.au/courses

  } 

} ) 

## 

## Start w/default asset set (empty key) 

#set( $assets = $assetsByCourse[""] ) 

## 

## Guard against bad inputs (null or empty object list) 

#if( $LeadList && !$LeadList.isEmpty() ) 

    ## 

    ## Loop backwards through objects (standard for each is fwd only) 

    #foreach( $idx in [$math.sub($LeadList.size(),1)..0] ) 

        #set( $Lead = $LeadList[$idx] ) 

        #foreach( $assetSet in $assetsByCourse.keySet() ) 

            ## 

            ## If we find a regex match for [map key,CourseCode] we're done 

            #if( $Lead.CourseCode.matches("(?i)${assetSet}") ) 

                #set( $assets = $assetsByCourse[$assetSet] ) 

                #break($foreach.parent) 

            #end 

        #end 

    #end 

#end 

"${assets.OCBURL}"

SanfordWhiteman
Level 10 - Community Moderator

Re: $TriggerObject usage according to documentation

What about a dump of $LeadList? Can't tell you what should match unless I see the input.

Mark_Westerman
Level 2

Re: $TriggerObject usage according to documentation

Sorry, I am new to this. I am just trying to send an email to a lead and include a url to the course they are interested in based on the Course Code on the Lead. I have had to resort to coding this because Marketo doesn't provide a way to insert a field from a custom object that is not directly related to the Lead.

Capture.PNG

SanfordWhiteman
Level 10 - Community Moderator

Re: $TriggerObject usage according to documentation

OK, so you don't have a $LeadList (array of COs) in this case, so nothing to iterate over. CourseCode is just a property on the Lead: $Lead.CourseCode

        #foreach( $assetSet in $assetsByCourse.keySet() ) 

            ## If we find a regex match for [map key,CourseCode] we're done 

            #if( $Lead.CourseCode.matches("(?i)${assetSet}") ) 

                #set( $assets = $assetsByCourse[$assetSet] ) 

                #break($foreach.parent) 

            #end 

        #end 

Mark_Westerman
Level 2

Re: $TriggerObject usage according to documentation

this is my modified script

## Set up your map of Courses to related asset(s) 

#set( $assetsByCourse = { 

  "5522US" : { 

    "OCBURL" : "http://www.csu.edu.au/courses/bachelor-of-science-honours

  }, 

  "1105PP" : { 

    "OCBURL" : "http://www.police.nsw.gov.au/recruitment/home

  }, 

  "" : { 

    "OCBURL" : "http://www.csu.edu.au/courses

  } 

} ) 

## 

## Start w/default asset set (empty key) 

#set( $assets = $assetsByCourse[""] ) 

## 

## Guard against bad inputs (null or empty object list) 

        #foreach( $assetSet in $assetsByCourse.keySet() ) 

            ## If we find a regex match for [map key,CourseCode] we're done 

            #if( $Lead.CourseCode.matches("(?i)${assetSet}") ) 

                #set( $assets = $assetsByCourse[$assetSet] ) 

                #break($foreach.parent) 

            #end 

        #end 

"${assets.OCBURL}"

It is still not giving my the correct url. I did notice that when I drag the Lead field over to the script editor in Marketo the syntax is ${lead.courseCode}.

SanfordWhiteman
Level 10 - Community Moderator

Re: $TriggerObject usage according to documentation

Yes, you should use Marketo's names for the fields and properties -- and they are case-sensitive. I can't know the site-specific names.

Mark_Westerman
Level 2

Re: $TriggerObject usage according to documentation

I understand.

I am not sure which version I should use;

If I use (without the curly brackets)

  #if( $lead.courseCode.matches("(?i)${assetSet}") )

I get this error

An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!

$foreach.parent is not a valid org.apache.velocity.runtime.directive.Scope instance near

?

If I use exactly as it inserts from Marketo

#if(${lead.courseCode}.matches("(?i)${assetSet}") )

I get this error

An error occurred when procesing the email Body!

Lexical error, Encountered: "m" (109), after : "." at *unset*[line 177, column 36] near

            ## If we find a regex match for [map key,CourseCode] we're done  
            #if(${lead.courseCode}.matches("(?i)${assetSet}") )  
                #set( $assets = $assetsByCourse[$assetSet] )  
                #break($foreach.parent)  
            #end  
SanfordWhiteman
Level 10 - Community Moderator

Re: $TriggerObject usage according to documentation

Use the first one (second is bad syntax) but I see the extra loop is referenced in there. Just use #break, not #break(<loopname>).