- 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 07:29 AM
Hi
Thank you, modified the "it should be getRequestItems and not checkRecordPresent at line 11 in client script"
I've added info message in script include and checked in logs, info message is showing but the RITM's are populating in catalog item.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 10:16 PM
Hi,
you didn't select any user?
Unless you select user the onChange won't run and won't show the RITMs
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 10:37 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 10:59 PM
Hi,
update as this and it will show RITM numbers
push number into array
arr.push(gr.getValue('number'));
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