Appending Values on a String field

morrix3
Giga Expert

Hello Master coders:
I am in need of a script that would allow me to pass values from fields in variables that are located in a RITM into a Standard Change Request field  (I am using a UI action to create the CHG Req from the RITM)

So for example:

Name = Snow

City= New York

Country = USA

I need the values to append to a Description Field that reads likes this:

Provide the following:
Name:
City:

Country: 

Basically I need to be able to pass the values of Name, City & Country into the predetermined text that is already populated into the Description Template and they should be placed correctly and after the colon.

I hope this makes sense and I appreciate any help.

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If your UI Action is running on the sc_req_item table, use current.variables.variable_name to access those values. As long as Name, City, and Country are all text variables, and assuming description is a long string field it's going to be easiest to wipe the field value and rebuild it with your variable values, so something like this

var name = current.variables.name;
var city = current.variables.city;
var country = current.variables.country;

var desc = 'Provide the following:\n Name: ' + name + '\nCity: ' + city + '\nCountry: ' + country;

Then use desc to update the field on the newly-created change request.  If name or any of these are reference variables, then you'd have to do a GlideRecord to lookup the display value first.

View solution in original post

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

You don't need any coding for this requirement.

You can use flow designer flows to update record with these appended values.

 

https://docs.servicenow.com/bundle/orlando-servicenow-platform/page/administer/flow-designer/referen...

 

Regards,

Sachin

 

This still doesn't help because the words/lines name, city & country are already there.  I just need to be able to collect the values and paste them after the colon ( : )

Brad Bowman
Kilo Patron
Kilo Patron

If your UI Action is running on the sc_req_item table, use current.variables.variable_name to access those values. As long as Name, City, and Country are all text variables, and assuming description is a long string field it's going to be easiest to wipe the field value and rebuild it with your variable values, so something like this

var name = current.variables.name;
var city = current.variables.city;
var country = current.variables.country;

var desc = 'Provide the following:\n Name: ' + name + '\nCity: ' + city + '\nCountry: ' + country;

Then use desc to update the field on the newly-created change request.  If name or any of these are reference variables, then you'd have to do a GlideRecord to lookup the display value first.

If i do this, wouldn't the name, city & the country be added again to the description field? remember that those lines/words are already there.

So i pretty much need to pass the values only and position them after the colon ( : ).

This is the problem I am having, the client wants no matter what those words to be there in the description template no matter what i say to them .

 I have not tried this yet but i guess i can give it a try and see if it wipes out what's already there/