- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:33 AM
Hello,
I have written a script in workflow and in that I have used the "replace" to replace the value in string value which I am getting through current.variables.
var Environment_Name = current.variables.Environment_Name ;
gs.info("varable value ",Environment_Name);
var env = Environment_Name.replace("Replace : ", "Hello");
variables.setDisplayValue('default_value',env);
variables.update();
Is there anything wrong with this script because it is storing "undefined " in the variable field.If I remove this "replace("Replace : ", "Hello")" then value stores perfectly in the variable. Can someone please tell where I am going wrong? Why is it showing undefined in variable value while using "replace"?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:39 AM
Hi Ishaan,
Try this... (bold indicates what I changed)
var Environment_Name = current.variables.Environment_Name.toString() ;
gs.info("varable value " + Environment_Name);
var env = Environment_Name.replace("Replace : ", "Hello");
variables.setDisplayValue('default_value',env);
// variables.update(); // No such method update() for variables object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:37 AM
Can you please provide some example data? For example is the Environment_Name variable a string and if so what is an example value?
This code isn't correct as "variables" isn't an available object:
variables.setDisplayValue('default_value',env);
variables.update();
You would need:
current.variables.default_value.setDisplayValue(env);
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:43 AM
Hi Michael,
This is the complete code.And assume sample data to be "Replace : xyz" and I want to remove "Replace : " and want to store "xyz" in that.
var variables=new GlideRecord("item_option_new");
var Environment_Name = current.variables.Environment_Name ;
gs.info("varable value ",Environment_Name);
var env = Environment_Name.replace("Replace : ", "Hello");
variables.setDisplayValue('default_value',env);
variables.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:39 AM
Hi Ishaan,
Try this... (bold indicates what I changed)
var Environment_Name = current.variables.Environment_Name.toString() ;
gs.info("varable value " + Environment_Name);
var env = Environment_Name.replace("Replace : ", "Hello");
variables.setDisplayValue('default_value',env);
// variables.update(); // No such method update() for variables object
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-05-2017 05:48 AM
Hi Chuck,
Thanks for your response,script has worked.