- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 02:43 AM
Hello!
I have a requirement to add a clone/copy an existing RITM record functionality in the Catalog Item View. The requirement is to add a Copy RITM checkbox. When this is selected, a dropdown variable will show all of the RITM records for the item. Selecting a record will populate all of the variables from the old RITM. Has this been done before?
Please help!
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 04:50 AM
Yes, its poosible.
function getRITMdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var SkipFieldValue = '|requested_by|on_behalf_of'; //here map your variable names which you dont want to copy
var jData = JSON.parse(answer);
for (var key in jData) {
if (SkipFieldValue.indexOf('|' + key + '|') == -1) {
g_form.setValue(key, jData[key], jData['dv_' + key]);
}
}
}
Thanks
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 03:02 AM
Hi,
you can use onChange catalog client script + GlideAjax and fetch all the variables from that RITM and use JSON structure in the script include so that when you parse you can set the form variables
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
‎03-22-2022 03:03 AM
You can create checkbox and reference variable and use UI policy to make it visible when checkbox is true and use Simple reference qualifier with Item is your catalog item and use GlideAjax and script include to get the ritm variables data. I'm used this code a long back, try if this works.
Onchange client script on RITM variable
function onChange(control, oldValue, newValue, isLoading) {
var ritm = g_form.getValue('ritm');
var ajax = new GlideAjax('Newglidingabc');
ajax.addParam('sysparm_name', 'getRITMDetails');
ajax.addParam('sysparm_ritm', ritm);
ajax.getXML(getRITMdata);
}
function getRITMdata(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
var jData = JSON.parse(answer);
for (var key in jData) {
g_form.setValue(key, jData[key], jData['dv_' + key]);
}
}
getRITMDetails: function() {
var ritm_number = this.getParameter('sysparm_ritm');
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(ritm_number);
set.load();
var vs = set.getFlatQuestions();
var object = {};
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getLabel() != '' && vs.get(i).getValue() != '') {
object[vs.get(i).getName()] = vs.get(i).getValue();
object['dv_' + vs.get(i).getName()] = vs.get(i).getDisplayValue();
}
}
var data = JSON.stringify(object);
return data;
},
Thanks
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 04:18 AM
This works! However, it is copying the values for Requested by and On Behalf of. Is there a way to not include specific variables when copying the values?
Many thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2022 04:48 AM
Hi,
the script is just fetching variable values
what is Requested By and On Behalf of? are those also variables?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader