SOLVED

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

Go to solution
shilpapradhan
Level 1

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? 

 

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

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

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.

View solution in original post

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

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

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 1

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

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 - Community Moderator

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

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.

shilpapradhan
Level 1

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

Thank you!