- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 09:58 PM
Hi there,
I have a simple catalog form where you can select the user and user's manager name should auto populate. Sometimes, manager is away for some reason, the requester should able to choose another manager from manager's drop down box.
I've seen script include and client script but it is not working.
My form will have
Requester - Reference field to sys_user table
Manager name - auto populate and ability to change from drop down box
Could you please advise? For manager dropdown box, should i create Reference field on sys_user table as well?
Can this be achievable? Thank you.
Script include: client callable
var getUserLineManager = Class.create();
getUserLineManager.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManager:function() {
var user = this.getParameter('sysparm_req');
var mgr = new GlideRecord("sys_user");
mgr.addQuery("sys_id", user);
mgr.Query();
if(mgr.next()){
return mgr.manager.toString();
}
} ,
type: 'getUserLineManager'
});
Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('approving_manager');
}
var ga = new GlideAjax('getUserLineManager');
ga.addParam('sysparm_name', "getManager");
ga.addParam('sysparm_req', g_form.getValue('requested_for'));
ga.getXMLAnswer(function(answer){
g_form.setValue("approving_manager", answer);
});
//Type appropriate comment here, and begin script below
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 10:04 PM
Zero code approach
https://community.servicenow.com/community?id=community_article&sys_id=3f0cf115db7fc190847d5ac2ca961931
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 10:04 PM
Zero code approach
https://community.servicenow.com/community?id=community_article&sys_id=3f0cf115db7fc190847d5ac2ca961931
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-05-2022 10:43 PM
Hi,
Yes it will not go to If loop in script include. Type error q is small not big one Q.
mgr.Query(); //it should be mgr.query();
Hope you it helps you.
Please Mark ✅ Correct/helpful if applicable, Thanks!!
Regards
Pavankumar
ServiceNow Community MVP 2024.
Thanks,
Pavankumar