Copy ritm variable details to ritm description
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 01:38 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 01:42 AM
Why background script? Is this for one time activity.
var ritmis=new GlideRecord('sc_req_item');
ritmis.addQuery('number','RITM....');//Replace RITM number correctly
ritmis.query();
gs.print(ritmis.getRowCount());
while(ritmis.next())
{
ritmis.description=ritmis.variables.description1;//replace description1 with variable name for description
ritmis.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 01:51 AM
Hi
To accomplish your requirement, you can use the below-provided code in Business Rule:
Name: Copy Variables to Description
When: Before
Insert: True
Condition: Item ► is not empty (or Item ► is ► <your required Catalog item>)
Script:
(function executeRule(current, previous /*null when async*/ ) {
var desc = current.description;
var descAppend = '';
for (var prop in current.variables) {
if (current.variables.hasOwnProperty(prop)) {
descAppend += prop + ': ' + current.variables[prop];
}
}
desc += '\n\nVariables Data:\n' + descAppend;
})(current, previous);
Please mark my answer as correct if this solves your issues!
If it helped you in any way then please mark helpful!
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 04:00 AM
Hi
Was I able to provide a solution to your question?
If yes and if my answer helped you out then please mark my answer as correct/helpful, so that other community members facing similar issues might get help.
Thanks and regards,
Kartik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2022 02:27 AM
so this is for existing RITMs where description field is not having the variable information
You can use this sample script for 1 record and then run it for all
var ritm = new GlideRecord('sc_req_item');
ritm.addEncodedQuery("descriptionISEMPTY");
ritm.setLimit(1); // first test for 1 record and then comment this line
ritm.query();
if(ritm.next()){
var arr = [];
var variables = ritm.variables.getElements();
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var label = question.getLabel();
var value = question.getDisplayValue();
if(label != '' && value != ''){
arr.push(label + ' : ' + value + '');
}
}
ritm.description = arr.toString();
ritm.update();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader