Notification Email Script getCompanyID return null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 10:16 PM
Hi All,
I have built notification email script
var GU_obj=gs.getUser();
var compid=GU_obj.getCompanyID();
template.print(compid);
I have tested this on "Scripts - BackGround",It returned the value as well.
I have called the script from email Notification body,When user received the email ,They received the value as null.
thnx.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:01 AM
it is giving you the company id for current user, for which user you want the information?
If you have the sysid of the user, you can pass that in getUserbyId function.
Lets say,
var userid = current.getValue("caller_id);
gs.info(gs.getUser().getUserByID(userid ).getRecord().getValue('company'));
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 11:16 PM
Primary question is whose company name you want to print?
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
07-14-2022 11:59 PM
Current logged in User

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2022 11:59 PM
Try this
var gr = new GlideRecord('sys_user');
if (gr.get(gs.getUserID())) {
template.print(gr.company);
}
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-15-2022 12:22 AM
Hi,
It doesn't make sense to use current logged in user in email script
Are you saying you want to get company for the recipient of that email? if yes then that's possible
something like this
var gr = new GlideRecord('sys_user');
gr.addQuery('sys_id', event.parm1).addOrCondition('sys_id', event.parm2);
gr.query();
if(gr.next()){
template.print(gr.company.name);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader