- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2022 03:00 AM
Hi ,
we have a catalog item (first RITM) that collects the info of devices (laptops and peripherals) for the new user. When the user is not joining, then there is a new catalog item (second RITM) which needs to collect all the devices provided in the previous request. How to show all the devices tagged to the person from first RITM in the second RITM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 02:41 AM
Hi,
I believe "devices_to_be_returned" is referring to model table
update as this
var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDevices: function() {
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
gr.query();
while (gr.next()) {
if (gr.variables.requested_on_behalf_of == user)
arr.push(gr.variables.model.sys_id.toString());
}
return arr.toString();
},
type: 'getMyDevices'
});
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
08-21-2022 10:24 PM
Hi,
you can query all RITMs and get the variable value for Model and push the record sysId and then return that and set the value
logic still remains the same just the approach will change based on your requirement
If my response helped please mark it correct and close the thread so that it benefits future readers.
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
08-21-2022 11:07 PM
Hi Ankur,
I made changes by copying the solution in above post but it is not showing all the devices tagged to this person (through RITM-1). The following is being shown.
For the devices to be returned, it should be a list collector field populated with all the devices he got from RITM-1.
Catalog client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('devices_to_be_returned');
if (oldValue != newValue) {
var ga = new GlideAjax('getMyDevices');
ga.addParam('sysparm_name', "getDevices");
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer) {
if (answer != '') {
g_form.setValue('devices_to_be_returned', answer);
}
});
}
}
script include:
var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDevices: function() {
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
gr.query();
while (gr.next()) {
if (gr.variables.requested_on_behalf_of == user)
arr.push(gr.variables.model.sys_id);
}
return 'sys_idIN' + arr.toString();
},
type: 'getMyDevices'
});
Please let me know the changes required
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2022 02:41 AM
Hi,
I believe "devices_to_be_returned" is referring to model table
update as this
var getMyDevices = Class.create();
getMyDevices.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getDevices: function() {
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name", "RITM 1"); // name of your catalog item
gr.query();
while (gr.next()) {
if (gr.variables.requested_on_behalf_of == user)
arr.push(gr.variables.model.sys_id.toString());
}
return arr.toString();
},
type: 'getMyDevices'
});
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader