Notification Email Script getCompanyID return null

Pratap Dalai
Kilo Explorer

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.

19 REPLIES 19

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'));

Best Regards
Aman Kumar

Ankur Bawiskar
Tera Patron
Tera Patron

@Pratap Dalai 

Primary question is whose company name you want to print?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Current logged in User

Try this

var gr = new GlideRecord('sys_user');
if (gr.get(gs.getUserID())) {
   template.print(gr.company);
}

Regards
Harish

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader