- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 12:03 AM
Hi,
I have two catalog items,
New Hire - with two variables (requested for (reference) , Model (reference)
Another catalog item,
Leaver - with variables(requested for, Request's related to user)
when requested for is selected, all RITM's of the requested user should be populated in another field.
Question:
1. what variable type is suggested to populate all RITM's of user.
2. How to achieve this.
Please help me in this.
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 01:39 AM
Hi,
you need to check the variable value for request on behalf of and not requested_for field
If you just want to display the RITMs then you can use single line text variable and populate the values as comma separated numbers
Use onChange client script + GlideAjax to set the variable present on Leaver catalog item
UI Type - ALL
Applies to Catalog Item - True
Variable - Requested on behalf of
Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == '')
g_form.clearValue('variableName');
if(oldValue != newValue){
var ga = new GlideAjax('getMyRequests');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_user', newValue);
ga.getXMLAnswer(function(answer){
if(answer != ''){
g_form.setValue('variableName',answer);
}
});
//Type appropriate comment here, and begin script below
}
}
Script Include:
var getMyRequests = Class.create();
getMyRequests.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getRequestItems: function(){
var user = this.getParameter('sysparm_user');
var arr = [];
var gr = new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name", "New Hire"); // name of your catalog item
gr.query();
while (gr.next()) {
if(gr.variables.requested_on_behalf_of == user)
arr.push(gr.getUniqueValue());
}
return arr.toString();
},
type: 'getMyRequests'
});
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-20-2022 12:28 AM
Hi @Sai
You will need a list collector field for this purpose and your reference table will be Requested Item table, and for auto-populating associated RITMs with a user, you will need to write an onChange client script, using AJAX to fetch the RITMs and pass that on to be shown in the newly created list collector field.
Your encoded query should be:
"request.requested_for="+ sys_id of the user// sys_id you will pass from the client script
For reference to AJAX:
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 01:15 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 07:15 AM
You will have to explicitly pass parameter from your client script to script include.
You can't pass functional parameters in AJAX, even in the reference link, the script example passes caller_id as additional data from client script in order fetch details for that specific user.
Feel free to mark correct, If I answered your query.
Will be helpful for future visitors looking for similar questions 🙂
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 12:42 AM
Hi @Sai
1 ) You have to use the reference field , Reference to the sc_request table. (Note : If you want to select only one request then reference field. otherwise list collector for multi select)
2) To achieve this you can write down below reference qualifier in your 'Request's related user' field:
javascript: 'requested_for=' +current.variables.request_on_behalf_of;
Please make corrections to the variable name. instead of 'request_on_behalf_of' write down your own variable name for 1st variable.
Please mark my answer as correct/helpful based on impact.
Regards,
Gunjan Kiratkar