How to Auto Populate Manager in catalog item request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2021 03:03 AM
I crated "Demo Catalog Project" Catalog Item and Some Variables in that item. If user selects any Requester(sys_user). Then Manager field (single line text) should be auto populated with requester Manager.
I created below catalog OnChange client script but auto populating only sys_id of Manager.
Please correct my script.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var user = g_form.getValue('requester');
var mgr = new GlideRecord("sys_user");
mgr.addQuery("sys_id", user);
mgr.addQuery();
while(mgr.next())
{
g_form.setValue("manager", mgr.manager);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-24-2021 02:50 AM
@krishna
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
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
03-12-2021 03:38 AM
Hi @krishna
Here you need to use GlideAJax approach.
create one script include and call that from client script.
make script include client callable.
var UserDetails = Class.create();
UserDetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getManager:function() {
var user = this.getParameter('sysparm_requster');
var mgr = new GlideRecord("sys_user");
mgr.addQuery("sys_id", user);
mgr.addQuery();
if(mgr.next()){
return mgr.manager.name;
}
} ,
type: 'UserDetails'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if(newValue == ''){
g_form.clearValue('manager');
}
var ga = new GlideAjax('UserDetails');
ga.addParam('sysparm_name', "getManager");
ga.addParam('sysparm_requster', g_form.getValue('requester'));
ga.getXMLAnswer(function(answer){
if(answer != ''){
g_form.setValue("manager", answer);
}
});
//Type appropriate comment here, and begin script below
}
Please mark reply as Helpful/Correct, if applicable. Thanks!
Regards,
Rameshwar khile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2021 03:58 AM
What's the point in copying and pasting my script as your reply?
Please avoid in future.
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
05-24-2021 01:26 AM
Hi there,
Any update on my response? Did this solve your question? Or do we need to follow-up on this?
Please mark this answer as correct if it solves your question. This will help others who are looking for a similar solution. Also marking this answer as correct takes the post of the unsolved list.
Thanks.
Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP
---
LinkedIn
Community article, blog, article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2021 10:00 PM
Hii
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('scipt_incl_catalog_item');
ga.addParam('sysparm_name', 'getname');
ga.addParam('sysparm_value', newValue);
ga.getXML(callback);
function callback(response) {
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue("manager",answer);
}
//Type appropriate comment here, and begin script below
}
var scipt_incl_catalog_item = Class.create();
scipt_incl_catalog_item.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getname: function() {
var np = this.getParameter('sysparm_value');
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id',np);
gr.query();
if(gr.next())
{
var manager = gr.manager.getDisplayValue();
}
return manager;
},
type: 'scipt_incl_catalog_item'
});
regards
Deepshikha Pandey