SOLVED

Re: URL Not Resolving in Email Script Token

Go to solution
adanand
Level 2

...

Tags (1)
1 ACCEPTED SOLUTION
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Hello @adanand, custom objects are stored in descending order of their created date. So the first custom object in the CO list would be the one that was added last, usually in almost all of the cases this does not get us anywhere, and hence we first sort the custom object list per our requirement (e.g., sort by updated date, a field, etc.) and then start working with the records in it (as once sorted we'd know the order of records in it). Additionally, are you assuming that a custom object can only contain 1 record? If so that's not true, a CO can contain n number of records, all of which together make a custom object list. Also, after sorting we aren't gonna grab the entire list, just the relevant field from a particular CO record.

 

Furthermore, what we mean by outputting the complete <a> through </a> is that you need to have something like the below in your velocity script (of course after doing the necessary sorting first):

 

<a href="https://${vMC_cList.get(0).performance_cta_url}?utm_medium=paid-social&utm_source=linkedin&utm_campaign=ABC_Test">Click here</a>

 

You can't just output just the URL from the CO field from a velocity token, then reference it in the email's link editor. You have to output the fully formed <a> tag from the velocity script itself.

 

I hope this is useful. Pls let us know if you have questions.

 

View solution in original post

30 REPLIES 30
adanand
Level 2

 

Hi @Darshil_Shah1 ,

 

The link we are sending to the Custom Object does not have https://

 

We have the protocol in the email body: href="https://{{my.VMC-PERFORMANCE-CTA-URL}}{{my.cta1-URLparams}}"

 

The velocity script token is : ${vMC_cList.get(0).performance_cta_url}

 

When I test the link: it is not picking up the performance_cta_url token value - it is literally pasting performance_cta_url token name in the link url as below

 

https://%24%7Bvmc_clist.get%280%29.performance_cta_url%7D%26utm_source%3Dmarketo%26utm_medium%3Demai...

 

I am not a velocity expert, but I need to get this link to work - is there no way to edit the above velocity token (without looping) just a simple direct way to get this link to work?

 

Many thanks

SanfordWhiteman
Level 10 - Community Moderator

You cannot create links like that. As noted elsewhere, the entire link needs to be output from Velocity.

 

That means the opening <a> through closing </a> is coming from your token. You can’t have some of the link outside of your token, and some of the link inside.

 

However, that’s only part of the problem. You’re also trying to output what looks like one arbitrary item: the first/0-th item in the list. Why is that — is there something special about the first item in an arbitrarily ordered list? (Hint: probably not!)

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Hello @adanand, custom objects are stored in descending order of their created date. So the first custom object in the CO list would be the one that was added last, usually in almost all of the cases this does not get us anywhere, and hence we first sort the custom object list per our requirement (e.g., sort by updated date, a field, etc.) and then start working with the records in it (as once sorted we'd know the order of records in it). Additionally, are you assuming that a custom object can only contain 1 record? If so that's not true, a CO can contain n number of records, all of which together make a custom object list. Also, after sorting we aren't gonna grab the entire list, just the relevant field from a particular CO record.

 

Furthermore, what we mean by outputting the complete <a> through </a> is that you need to have something like the below in your velocity script (of course after doing the necessary sorting first):

 

<a href="https://${vMC_cList.get(0).performance_cta_url}?utm_medium=paid-social&utm_source=linkedin&utm_campaign=ABC_Test">Click here</a>

 

You can't just output just the URL from the CO field from a velocity token, then reference it in the email's link editor. You have to output the fully formed <a> tag from the velocity script itself.

 

I hope this is useful. Pls let us know if you have questions.

 

adanand
Level 2

Hi

 

I have a follow on question on velocity link token please 

 

In a velocity script token, I am using the following velocity link token code and in the email body just has the reference to this below link token as text {{my.link}} in the email body. The link as used like this is clicking and tracking both :-

 

<a href="https://${vMC_cList.get(0).op_tip2_cta_url}&utm_source=marketo&utm_medium=email&utm_campaign=m&utm_content=na&utm_term=advanced_email">${vMC_cList.get(0).op_tip2_cta_text}</a>

 

Now, I have a use case where sometimes the Custom Object data may not have a link cta text and cta url. In that case, when the Custom Object data for cta text and cta url shows as &nbsp; then the email body shows a hyperlinked '-' broken link with params as above.

 

I want to be able to create a rule in the velocity script link token such that when the Custom Object field for cta url and cta text shows &nbsp; (&nbsp; as signifying a blank value in the Custom Object cta text and cta url fields) then show nothing in the email body (so I can avoid the broken hyperlink '-' in the email body)

 

Please advise

 

Thanks

SanfordWhiteman
Level 10 - Community Moderator

Please show the output (not expurgated or altered) of ${vMC_cList} in which one item has the literal string nbsp; in the relevant fields.

adanand
Level 2

Hi,

Continuing from this post above, could you please advise if that the way one can pull Custom Object fields (of hyperlink link and hyperlink text) into a Velocity Script token to make one script token pulled into an email. This is possible with Custom Object fields. 

eg using the two hyperlink link and hyperlink text Custom Object fields to work together to form a hyperlink in an email by placing the script token {{my.CTA-URL}} in the email.

cta_url:

 

{{my.CTA-URL}}

<a href="https://${List.get(0).cta_url}&utm_source=marketo">${vMC_cList.get(0).op_tip1_cta_text}</a>##
cta_text

{{my.CTA-TEXT}}

{{my.CTA-TEXT}}

I wanted to ask if the above use case is also possible using a text token or a rich text token, in the absence of Custom Object fields to pull into the a href above?

Thanks

adanand
Level 2

Hi @SanfordWhiteman @Darshil_Shah1 ,

Hope you are doing well. Wanted to check with you in case you can please share any insight on the below :-

Background: Continuing from this post above, could you please advise if the way one can pull Custom Object fields (of hyperlink link and hyperlink text) into a Velocity Script token to make one script token pulled into an email. This is possible with Custom Object fields. 

eg using the two hyperlink link and hyperlink text Custom Object fields to work together to form a hyperlink in an email by placing the script token {{my.CTA-URL}} in the email.

cta_url:

 

{{my.CTA-URL}}

<a href="https://${List.get(0).cta_url}&utm_source=marketo">${vMC_cList.get(0).op_tip1_cta_text}</a>##
cta_text

{{my.CTA-TEXT}}

{{my.CTA-TEXT}}

My question is : I wanted to ask if the above use case is also possible using a text token or a rich text token, in the absence of Custom Object fields to pull into the a href above? Or can I use an ad hoc custom object field in the email program to make the hyperlink for the email, which token gets loaded through API?

Thanks

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

@adanand wrote:

Hi @SanfordWhiteman @Darshil_Shah1 ,

Hope you are doing well. Wanted to check with you in case you can please share any insight on the below :-

Background: Continuing from this post above, could you please advise if the way one can pull Custom Object fields (of hyperlink link and hyperlink text) into a Velocity Script token to make one script token pulled into an email. This is possible with Custom Object fields. 

eg using the two hyperlink link and hyperlink text Custom Object fields to work together to form a hyperlink in an email by placing the script token {{my.CTA-URL}} in the email.

cta_url:

 

{{my.CTA-URL}}

<a href="https://${List.get(0).cta_url}&utm_source=marketo">${vMC_cList.get(0).op_tip1_cta_text}</a>##
cta_text

{{my.CTA-TEXT}}

{{my.CTA-TEXT}}

My question is : I wanted to ask if the above use case is also possible using a text token or a rich text token, in the absence of Custom Object fields to pull into the a href above? Or can I use an ad hoc custom object field in the email program to make the hyperlink for the email, which token gets loaded through API?

Thanks


Hi @adanand - yes, I'm well! Thank you for asking! Hope you're well too!

 

I'm a bit unclear about your exact ask, so I'm gonna answer based on my understanding of your question and try to cover all the possible scenarios I can think of:

 

First, you can't reference the text my token in the velocity, but, you can pass through a value to multiple email scripts using a macro. https://velocity.apache.org/engine/1.7/user-guide.html#velocimacros.

 

This is likely overkill for what you are trying to do as you can simply define the URL value in your primary script token, but it might be worth it if you had many email script tokens that were dependent on that URL token or don't want people to open up your email script token with the logic just to update the URL.

 

Also, secondly, if your URL value is in the custom object, then you'd have to reference it using the email script token only, can't use the simple text/rich text tokens. Also, fields on objects other than the CO maintain a 1-1 relationship with the person, or in the case of a custom token, the token value is managed at the program level, unlike the custom object, you can't associate multiple values for the same attribute with the same person record (1-n relationship). There's a way to store data in a structured format (e.g., JSON) in the custom fields, but again you'd need velocity to parse it!

 

I hope this answers your question, if not, or if you have any further questions, please feel free to let us know and we'd be happy to help!

SanfordWhiteman
Level 10 - Community Moderator

Why are you seeking the first item (.get(0)) in the list? What’s special about that item?

 

In general, you should not be accessing the first item unless you have first sorted the list in a deliberate way — yes, even if you believe there will only be one item in the list, you should still sort it because Marketo itself cannot guarantee there’s only one.

adanand
Level 2

Thanks so much for replying @SanfordWhiteman . I'll check and get back

Thanks!

Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Well, what are the data in the URL and CTA text CO object fields in the CO record when they're blank? Is it "-" or null? Based on that we can define the if condition. You can print the VMC CO List ${vMC_cList} where you've blank values and check if you aren't sure.

 

For allowing only standard non-null and non-empty values, you could use the following condition:

 

#if(!$vMC_cList.get(0).op_tip2_cta_url.isEmpty() && $vMC_cList.get(0).op_tip2_cta_url && !$vMC_cList.get(0).op_tip2_cta_text.isEmpty() && $vMC_cList.get(0).op_tip2_cta_text)
<a href="https://${vMC_cList.get(0).op_tip2_cta_url}&utm_source=marketo&utm_medium=email&utm_campaign=m&utm_content=na&utm_term=advanced_email">${vMC_cList.get(0).op_tip2_cta_text}</a>
#end

 

 The script would only print the link if both $vMC_cList.get(0).op_tip2_cta_url and $vMC_cList.get(0).op_tip2_cta_text are non-empty and non-null.

 

adanand
Level 2

Hi @Darshil_Shah1 , @SanfordWhiteman ,

I much appreciate your response and guidance and have gotten the link to work and track.

 

To get the links to work:

VELOCITY TOKEN :

I input this in the velocity token code below and checked the variables op_tip1_cta_url and op_tip1_cta_text on the right side where all VMC custom object fields are listed inside the velocity token.

<a href="https://${vMC_cList.get(0).op_tip1_cta_url}&utm_source=marketo&utm_medium=email&utm_campaign=mid_6118&utm_content=na&utm_term=advanced_email">${vMC_cList.get(0).op_tip1_cta_text}</a>##

 

REFERERRED the above velocity token in the email as : {{my.VMC-OP-TIP1-CTA-URL}}

 

However, I am concerned about not having done the sort - as you said, without sorting, there's a fair possibility that you might reference the wrong data in your email. sorting is done via the velocity's sort tool for use in the script. By default the COs are stored in the descending order of their created order. If a person has multiple custom object records associated with them, out of all those, which of the record would you like to be considered for populating the correct URL? ---> are you please able to share what am I to implement this sort - is it done inside another additional new velocity token? 

 

Are you able to advise on how to implement sorting, in the above case where links are working and tracking for one test record

 

Many thanks,

 

Aditi

 

SanfordWhiteman
Level 10 - Community Moderator

That’s why I keep asking Which item in the list is the one you want to output?

 

This is a business question. We can’t tell you that you want output the most recently updated one... or the first created one... or the earliest created one that also has a field set to a specific value.

 

Your answer to this question determines how to execute the sort.

adanand
Level 2

Hi @Darshil_Shah1 ,

 

Many thanks for your response

 

Assuming I use this code in the velocity token :

<a href="https://${vMC_cList.get(0).performance_cta_url}?utm_medium=paid-social&utm_source=linkedin&utm_campaign=ABC_Test">Click here</a>

 

How do I reference this code in the HTML editor? : ??

 

Currently I have this in the HTML editor : have the protocol in the email body: The link we are sending to the Custom Object does not have https:// to enable tracking :

href="https://{{my.VMC-PERFORMANCE-CTA-URL}}{{my.cta1-URLparams}}"

 

Thanks,

 

Aditi

 

 

Tags (1)
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Please reference the velocity token in the email editor. So, if your velocity token is {{my.link}}, just add it wherever you wish to output the link in the email. You don't need to insert it via the "Insert/Edit Link" option in the Rich text, just insert the velocity token at the apt. space, and you should be golden. Also, please copy the UTM parameters from your existing {{my.cta1-URLparams}} token and add them to the URL in your velocity token. Also, I hope you got an idea about the importance of sorting, right? As w/o it, there's a fair possibility that you might reference the wrong data in your email.

 

adanand
Level 2

Hi @Darshil_Shah1 

 

Many thanks for this 

 

There are 70 fields in this Custom Object - with 10 links - are you please able to elaborate on the sorting aspect? 

Where do I sort these 70 fields on the Custom Object - is this also done via the velocity script?

 

Thanks,

 

Aditi

adanand
Level 2

Hi @Darshil_Shah1 

 

Many thanks for this

 

Your note helped resolve the issue - now not only are the links working, they are tracking as well.

 

Thanks,

 

Aditi

Tags (1)
adanand
Level 2

Hi @SanfordWhiteman ,

 

Thank you so much

Tags (1)
Darshil_Shah1
Level 10 - Community Advisor + Adobe Champion

Yes, sorting is done via the velocity's sort tool for use in the script. As I said earlier, by default the COs are stored in the descending order of their created order.

 

If a person has multiple custom object records associated with them, out of all those, which of the record would you like to be considered for populating the correct URL? Would it be the most recently updated custom object record or something else?

 

adanand
Level 2

Hi @SanfordWhiteman 

Thanks for your response

Are you please able to share how to edit this velocity script token is : ${vMC_cList.get(0).performance_cta_url} 

 

to meet the condition below

 

That means the opening <a> through closing </a> is coming from your token. You can’t have some of the link outside of your token, and some of the link inside. 

 

I am not a velocity expert and will appreciate if you can please share the answer here

 

Thanks,

Aditi