Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to replace string with another in variable while submitting a catalog item

User12975
Tera Contributor

Hi Mates,

 

I have an issue where in when a & is added in a variable of the catalog item its shown as &

 

I ant to replace it each time when catalg item is submitted ,

 

Hence created a script and used in business rule somehow does not seems to be working .

 

Can someone expert will help here ?

 

 

(function executeRule(current, previous /*null when async*/) {

    var roc = current.variables.variable_name.getDisplayValue();
    roc = roc.replace(/&/g, "&");
    current.variables.variable_name = roc;


})(current, previous);

 

variable_name is the name of the variable

7 REPLIES 7

Tried the same in PDI & it works.

Did you still manage to apply logs & check for values received. Also, I am assuming BR is on RITM table.

RaghavSh
Mega Patron

 var roc = current.variables.variable_name.toString()

Try using current.variables.variable_name, without display value. The replace function works on string.


Raghav
MVP 2023
LinkedIn

Did you try to replace if after converting the variable to string?


Raghav
MVP 2023
LinkedIn