The CreatorCon Call for Content is officially open! Get started here.

want to populate from to fields as logged user email id

Aarushi1991
Tera Contributor

Folks,

 

i am a having a Quick message where i am trying to populate from text as : logged user email id

 

Aarushi1991_0-1743145498939.png

 

 

email script :

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here


    var user= gs.getUserID();
    var usertable= new GlideRecord("sys_user");
    usertable.get(user);
    usertable.query();
    if(usertable.next()){
        var emailid=usertable.email;
    }
    gs.info("Email id"+emailid);
template.print(email);


})(current, template, email, email_action, event);
 
 
When i try to call same email script in notification is coming like this (when i preview email )
 
Aarushi1991_1-1743145652299.pngAarushi1991_2-1743145672477.png

 

 

this email script when i run in background script its giving email id but nt in quick message and notification

 

 

Thanks

 

 

 
 
1 ACCEPTED SOLUTION

@Aarushi1991 - Please refer the screenshot below for the result after using ${current_user.email} in quick message

VasantharajanN_0-1743148909949.png

 


Thanks & Regards,
Vasanth

View solution in original post

12 REPLIES 12

Vasantharajan N
Tera Sage
Tera Sage

@Aarushi1991 - issue with your mail script ttemplate.print(email);

 

Please replace with right variable "emailid". It should be template.print(emailid);


Thanks & Regards,
Vasanth

Ankur Bawiskar
Tera Patron
Tera Patron

@Aarushi1991 

update as this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    var user= gs.getUserID();
    var usertable= new GlideRecord("sys_user");
    if(usertable.get(user)){
        var emailid = usertable.email.toString();
template.print(email);
    }
})(current, template, email, email_action, event);

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hello @Ankur Bawiskar ,

 

Still same in Quick message

Aarushi1991_0-1743148327744.png

 

In Notification is coming like

 

Aarushi1991_1-1743148391842.png

 

 

@Aarushi1991 - for quick message please use ${current_user.email} 

VasantharajanN_0-1743148774881.png

 


Thanks & Regards,
Vasanth