SOLVED

Re: Velocity Scripting - Help

Subscribe
Go to solution
ashah123
Level 3

Velocity Scripting - Help

Hi Team ,

 

We have a field at opportunity level which is a custom field and we want to display that value in the body of the email , when we use velocity script in the email script token with that value it gives us 35000.0 , but we would like to display as 35,000 . Can you help me how this can be fixed ?

ashah123_0-1752179183249.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - Help


Just noticed one thing if i add a token in the body ${{my.formattedAmount}} like this it gives an error but if i give $ {{my.formattedAmount}} then it works not sure if thats the issue ?

Of course. If you use the prefix ${ that conflicts with Marketo’s email variable syntax.

 

Do don’t put the dollar sign outside the Velocity token. Add it to the format string (since in fact, it is part of the format!)

${number.format("${esc.d}${esc.h}${esc.h},${esc.h}${esc.h}${esc.h}",$yourField)}

 

 

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - Help

Not providing your (attempted) code, nor even the datatype of this field, makes it harder to provide useful help!

 

If the field is a Float, Currency, or Integer, you want

${number.format("${esc.h}${esc.h},${esc.h}${esc.h}${esc.h}",$yourField)}

but impossible to say for sure.

 

Please remember to provide more technical details in community threads.

ashah123
Level 3

Re: Velocity Scripting - Help

@SanfordWhiteman 

I apologize for not providing more details in this thread.

 

The field type is set to currency.

 

Yesterday, I tested some code based on suggestions from ChatGPT, but I am unable to locate those details to share with you at the moment.

 

I also tested the code you provided, which indicated it might be compatible with the currency data type. When I included the email script token  (adding the code you shared in the script) in the subject line, it returned the correct value in the proper format, for example: 35,000.

 

But i want to use it in the body of the email at different places and when i add that token in the code of the HTML it gives me variable not defined error 

ashah123_0-1752234620251.png

 

Additionally, I would like to include the dollar sign with the amount in the body of the email, so it should appear as $35,000.

 

Could you please assist me in finding a solution for this?

 

Lastly, while I was adding the token, I encountered an error stating that the images do not have a mktoname. This was unexpected, as we are hosting them on our company server. I'm unsure if this error is related to the use of the token.

 

Apologies once again for not sharing the entire details

Looking forward to your response

Regards,

Akshat

 

ashah123
Level 3

Re: Velocity Scripting - Help

Just noticed one thing if i add a token in the body ${{my.formattedAmount}} like this it gives an error but if i give $ {{my.formattedAmount}} then it works not sure if thats the issue ?

 

Additionally when i preview this is how it displays with the tokens and it make the width longer , i guess it will work as expected when we render with a actual lead which has a value against it right ?

ashah123_0-1752242901844.png

 

I just tried using the below and it gives me the result , let me know if something looks unappropriate to you 

 

Token used :

ashah123_0-1752243349948.pngashah123_1-1752243368077.png

This is the code : $${number.format("${esc.h}${esc.h},${esc.h}${esc.h}${esc.h}", $OpportunityList.get(0).new_approvedworkingcapitaltotalamount)}

 

Just added a extra $ before the toke you shared

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - Help


Just noticed one thing if i add a token in the body ${{my.formattedAmount}} like this it gives an error but if i give $ {{my.formattedAmount}} then it works not sure if thats the issue ?

Of course. If you use the prefix ${ that conflicts with Marketo’s email variable syntax.

 

Do don’t put the dollar sign outside the Velocity token. Add it to the format string (since in fact, it is part of the format!)

${number.format("${esc.d}${esc.h}${esc.h},${esc.h}${esc.h}${esc.h}",$yourField)}

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting - Help


Yesterday, I tested some code based on suggestions from ChatGPT, but I am unable to locate those details to share with you at the moment.

There’s a 0% chance that ChatGPT will give you usable code for Marketo’s Velocity environment. Don’t use it.

 


Lastly, while I was adding the token, I encountered an error stating that the images do not have a mktoname. This was unexpected, as we are hosting them on our company server. I'm unsure if this error is related to the use of the token.

This cannot be related to the use of Velocity {{my.tokens]} for formatting. You might want to open a new thread about it.

ashah123
Level 3

Re: Velocity Scripting - Help

Thanks @SanfordWhiteman This helps

Let me try the new code you shared and test it out 

 

Thankyou so much for your help once again

Have a nice weekend ahead !!

 

Regards,

Akshat