- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2020 09:47 PM
Hello all,
Please correct me the code for variable details copy to RITM description , we are using below script.
workflow run script:
var variablesGR = new GlideRecord('sc_req_item');
variablesGR.get('sys_id', current.sys_id);
current.description = JSON.stringify(new GlideRecordToObject().toObject(variablesGR.variable_pool));
Script include :
var GlideRecordToObject = Class.create();
GlideRecordToObject.prototype = {
initialize: function() {
},
/**
* @summary toObject function returns a gliderecord as an object. This
* is used to prevent saving the place in memory.
* https://community.servicenow.com/community/develop/blog/2015/09/24/community-code-snippets--gliderecord-to-object-array-conversion
* @param {object} recordToPackage - The gliderecord object
* @return {object} JSON object that can be used.
*/
toObject : function(recordToPackage){
var packageToSend = {};
for (var property in recordToPackage) {
try {
if(property == 'work_notes' || property == 'comments'){
packageToSend[property] = recordToPackage[property].getJournalEntry(1);
} else {
packageToSend[property] = recordToPackage[property].getDisplayValue();
}
}
catch(err){}
}
return packageToSend;
},
type: 'GlideRecordToObject'
};
its working fine but when i got variables information like below.
{"requested_by":"Self","requested_for":"","business_service_name":"Test","business_owner_name":"Nitya","short_description":"test-short description","description":""}
Its taking backend variable names
But we need like below ( variable , next line another variable)
Requested by - Self
Requested for -
Business service name - Test
Business Owner - Nitya
Short description - est-short description
please correct me the code.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2020 12:26 AM
Hi Nitya,
please try this below script
you can add this code to before insert BR on sc_req_item table
Condition: current.cat_item == 'Your Catalog Item SysId'
var variables = current.variables.getElements();
var str = '';
for (var i=0;i<variables.length;i++) {
var question = variables[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
current.short_description = str;
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 01:22 AM
Hello @Elizabeth10 ,
You can use below logic to copy variable set(multi row variable set variables) to copy in description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 01:37 AM
Hi -
I managed to get it to work with this:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-23-2024 01:27 AM
Hello @Elizabeth10 ,
You can use below logic to copy variable set(multi row variable set variables) to copy in description.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2020 10:56 PM
Hi Nitya,
Hope you are doing good.
Did you get a chance to check on the solution provided to resolve your query?
If your query is resolved please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader