- 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:47 AM
Hi @Sai
1 ) You have to use the reference field , Reference to the sc_request table.
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
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 12:53 AM
A list collector would be a good as
You could also just use a text box and separate the reference numbers with commas: RITM0012345, RITM0012346, RITM0012347 etc.
With the latter solution, you'd still need to do a Glide Record lookup to get your list and then push it to the text box.
- 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 05:57 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2022 06:50 AM
Hi,
you are calling wrong function name in GlideAjax
it should be getRequestItems and not checkRecordPresent at line 11 in client script
are you using correct variable name to compare at line 13?
that variable should be from New Hire catalog item
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader