Can we change the data value of a lead field through Velocity Script? | Community
Skip to main content
shilpapradhan
Level 2
July 11, 2024
Solved

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

  • July 11, 2024
  • 1 reply
  • 1632 views

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.
Best answer by SanfordWhiteman

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.

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
Level 10
July 11, 2024

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.

shilpapradhan
Level 2
July 11, 2024

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

 

 

SanfordWhiteman
Level 10
July 11, 2024

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.