- 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
‎10-18-2023 02:47 PM
In the above code which you shared
where did you written the function getdata() ?
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 06:50 AM
Hi Murthy!
I didn't realize that was needed (novice coder)
Could you guide me in creating it? or send me in the right direction?
Any help is appreciated.
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-23-2023 06:52 AM
Hi Murthy!
Thanks for taking a look. I am a novice coder and didn't realize what i was missing.
Could you help me out in with writing the getdata function? or send me in the correct direciton?
Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-25-2023 03:47 PM
No issues. I can help you out here.
Create a on change client script on RITM variable like below:
function onChange(control, oldValue, newValue, isLoading) {
var ritm = g_form.getValue('ritm'); //here replace with your RITM variable name
var ajax = new GlideAjax('Newglidingabc'); //script include name
ajax.addParam('sysparm_name', 'getRITMDetails'); //function name
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]);
}
}
Now create a script include with client callable and use the below function:
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;
},
Let me know if you stuck anywhere. Happy to help:)
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2023 06:47 AM
Hi Murthy!
I really appreciate your help and i feel like its almost there, but still not working.
Let me share with you what I have:
RITM variable name that is pulling in the RITM to copy = ritm
scripts includes name =copyddu
my on change script, with "ritm: selected as the variable, and the box checked for Catalog item view
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ritm = g_form.getValue('ritm'); //here replace with your RITM variable name
var ajax = new GlideAjax('copyddu'); //script include name
ajax.addParam('sysparm_name', 'getRITMDetails'); //function name
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]);
}
}script inlcudes names copyddu
function getRITMDetails() {
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;
}
I have been playing with this all morning and have not made any progress (other then getting rid of a javascript error on the browser from another faulty script)
Any ideas here?
Thanks!!
Colin