- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:39 PM
Hi All,my task is while selecting manager field then automatically manager's location and company details will populated in specific field but it not working, kindly find my script include & client script
script include:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:56 PM
location is from user table and not company table
so update script as this
var Autopopulate = Class.create();
Autopopulate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompanyAndlocation: function(){
var caller = this.getParameter('sysparm_caller');
var grUser = new GlideRecord('sys_user');
if(grUser.get(caller)){
var usrobj = {};
usrobj.company = grUser.company.toString();
usrobj.location = grUser.location.getDisplayValue();
return JSON.stringify(usrobj);
}
},
type: 'Autopopulate'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:55 PM
Hi there,
What exactly is not working? Are you running into an error? Not getting any details? Etc? What information can you share?
Have you also tried debugging your script? Doing so, will shorten your search (and ours 😁) immensely.
Kind regards,
Mark
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
04-19-2023 09:56 PM
location is from user table and not company table
so update script as this
var Autopopulate = Class.create();
Autopopulate.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompanyAndlocation: function(){
var caller = this.getParameter('sysparm_caller');
var grUser = new GlideRecord('sys_user');
if(grUser.get(caller)){
var usrobj = {};
usrobj.company = grUser.company.toString();
usrobj.location = grUser.location.getDisplayValue();
return JSON.stringify(usrobj);
}
},
type: 'Autopopulate'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2023 09:57 PM
Just browsing your script VERY quickly, I did notice several not-best practices.
getXML => Use getXMLAnswer
setValue on references => User the second parameter
.get => Wrap this in an If statement
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field