- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 09:42 AM
Hi All,
I have requirment which need to copy the all RITM varibles to sc_task worknotes.
Could you please help on this to achive the requirment.
Thanks all,
Varma
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2022 12:58 AM
@varma2 Please try below updated code. It will fix the issues.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 11:37 AM
Hi @varma2
Create before insert business rule in sc_task table as below :Script :--
// Get the sys_id of the related RITM record
var ritmSysId = current.request_item.sys_id;
// Get the RITM record
var ritm = new GlideRecord('sc_req_item');
ritm.get(ritmSysId);
// Initialize an array to hold the variable names and values
var variables = [];
// Loop through all the variables in the RITM record
ritm.variables.variables.forEach(function(variable) {
// Add the variable name and value to the array
variables.push(variable.getName() + ': ' + variable.getValue());
});
// Concatenate the array into a single string
var workNotes = variables.join('\n');
// Set the work notes field of the sc_task record
current.work_notes = workNotes;
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 10:33 PM
I was implimented the code but its not working, variables not copy to the work notes on sc_task. even i was try to give decription it's not copying variables
please suggest.
Thanks,
Varma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 11:43 AM
Hi,
You can write the below code in workflow/flow or you can write a on Before insert BR (If you need this functionality for all catalogs)
var vs = new GlobalServiceCatalogUtil().getVariablesForTask(tr, true); //tr is the GlideRecord object of the target task here it is RITM GlideRecord object
var notes="";
for (var i=0; i < vs.length; i++)
{
var isMRVS=lbl=vs[i].multi_row+"";
var lbl=vs[i].label+"";
var dis=vs[i].display_value+"";
var visible=vs[i].visible_summary+"";
if(isMRVS=='true')
{
var vArr=vs[i];
notes+= lbl +"\n";
for (var j=0; j < vArr.table_variable.length; j++)
{
notes+="Row " + (j+1) + "\n";
var tblArr=vArr.table_variable[j];
for (var k=0; k < tblArr.length; k++)
{
var mrvslbl=tblArr[k].label+"";
var mrvsdis=tblArr[k].display_value+"";
if(mrvslbl != '' && mrvsdis!='' && mrvsdis!='false')
{
notes+= mrvslbl + ": " + mrvsdis + "\n";
}
}
notes+= "\n";
}
}
else
{
if (lbl != '' && dis!='' && dis!='false' && visible=='true') {
notes+=lbl + ": " + dis + "\n";
}
}
}
//notes is the variable that contains all the variables with its values including multi row variable set.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2022 10:31 PM
Hi Saurabh,
I was implimented the code but its not working, variables not copy to the work notes. please suggest.
Thanks,
Varma