Skip to main content
shilpapradhan
Level 2
Jul 11, 2024 7:47 PM UTC
Solved

Can we change the data value of a lead field through Velocity Script?

We have a specific language requirement for certain types of emails and I am trying to update a lead field with a code for the the language sent in the email for a consumer.   

#if (${lead.accntsolflag}=="1" && ${lead.crlcccode}=="N" && ${lead.cnsmrlangspkn}=="E") Disclosure Text1 #set ($SOLDisclosureID = "1") ${lead.SOLDisclosureID} = $SOLDisclosureID #end

Is it possible to update the lead field in velocity script? 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
SanfordWhiteman
SanfordWhitemanAccepted solution
User Group Leader
Jul 11, 2024 8:23 PM UTC

Please use the Syntax Highlighter (“Insert/Edit Code Sample” button) when posting code so it’s readable. I edited your post this time.

 

Your code has a number of errors, but fundamentally if your question is “Can I permanently change the value of a field in Velocity” the answer is No. Velocity can change the way a field is formatted in an email (and a million other things). It can’t change values in the database — it only sees a copy of the field values and can’t write back to the db.

 

You shouldn’t be using formal notation (${variable}) inside #directives, and should be using .equals() instead of ==. Not sure what you expect that code to do, of course, so it’s hard to correct it in full.

4 replies

SanfordWhiteman
User Group Leader
SanfordWhitemanUser Group LeaderAccepted solution
User Group Leader
Jul 11, 2024 8:23 PM UTC

Please use the Syntax Highlighter (“Insert/Edit Code Sample” button) when posting code so it’s readable. I edited your post this time.

 

Your code has a number of errors, but fundamentally if your question is “Can I permanently change the value of a field in Velocity” the answer is No. Velocity can change the way a field is formatted in an email (and a million other things). It can’t change values in the database — it only sees a copy of the field values and can’t write back to the db.

 

You shouldn’t be using formal notation (${variable}) inside #directives, and should be using .equals() instead of ==. Not sure what you expect that code to do, of course, so it’s hard to correct it in full.

Translate
shilpapradhan
Level 2
Jul 11, 2024 9:00 PM UTC

Thank you for the response and editing my post , I will make sure to use Syntax Highlighter next time. Is there a reason why we should use .equals() instead of == ? I tested below code and it works as expected.

 

#if (${lead.accntsolflag}=="1" && ${lead.crlccreditreportinglangcode}=="B" && ${lead.cnsmrlangspkn}=="E") Disclosure Test Sample1. #end

 

 

Translate
SanfordWhiteman
User Group Leader
User Group Leader
Jul 11, 2024 9:10 PM UTC

The specific case of comparing String constants to String properties works. There are many other cases where the outcome will surprise you because of String coercion — more thorough testing will reveal those. .equals() has no surprises because it never coerces.

Translate