- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 05:44 AM
Hi All,
I have a requirement that need to autopopulate user's company based on the logged user as default value , Actually on the Record producer there is account field that refered to Account table, and in the user form there is field company which also refered to account table,
My requirement was need to autopopulate that user's company into this account field of RP based on logged user?
Please help me to achieve this
Thanks
Hemachandra
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 08:35 AM
Hi @hemachandra2 ,
you can try below.
Catalog client script:
function onLoad() {
var ga = new GlideAjax('getaccount');
ga.addParam('sysparm_name', "getaccount");
ga.getXMLAnswer(function(answer) {
g_form.setValue("account", answer);//account catalog variable name
});
}
Script Include: In script include check client callable true.
var getaccount = Class.create();
getaccount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getaccount: function() {
var usr = new GlideRecord("sys_user");
usr.addQuery("sys_id", gs.getUserID());
usr.query();
if (usr.next()) {
return usr.account.toString(); //give backend value of account
}
},
type: 'getaccount'
});
Screenshot:
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:00 AM
Have you tried anything?
You can easily achieve this without any script.
Use catalog data lookup definition functionality.
Look at this below article:
Hope it helps..
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:06 AM
Hi @Murthy Ch
Thanks for the response
basically in that link it will set based on the requested for, but in my case , on the RP i don't have "Requested for " field, i need to populate company based on logged user only?
Thanks
Hemachandra
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:10 AM
Then you can write onload CS and script include to populate the company value.
If you are working in global scope use the logic which is given by @Rajesh Chopade1
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-13-2022 06:19 AM