- 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
‎01-16-2024 09:06 PM
you can iterate over those records and use the similar logic.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 02:26 AM
OK, so we have a field called 'case variable summary' and this will pull the variables using your business rule.
var gd = new GlideRecord('case');
var a = gd.addNullQuery('case_variable_summary');
a.addCondition('active','true');
gd.query();
while(gd.next())
{
var varSum = current.varSum.getElements();
var str = '';
for (var i=0;i<varSum.length;i++) {
var question = varSum[i].getQuestion();
var variableLabel = question.getLabel();
var variableValue = question.getDisplayValue();
str = str + variableLabel + ' - ' + variableValue + '\n';
}
current.case_variable_summary = str;}
gd.update();
Applying the logic in your BR to this the top line returns a NULL value, so that section of the JS doesn't work. Baring in mind my JS skills are novice at best, I'm hitting a brick wall at the moment.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-19-2024 03:12 AM
for existing records you need to have scheduled job
Could you post a new question and tag me there so that we can continue discussion there as this is an older thread?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-26-2024 04:21 AM
What if want to copy variables from variable set in RITM description?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2024 11:55 PM
Did you find a solution for copying variables from variable set to RITM description? I am trying to do the same, but the scripts above are not working for me.