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

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

VasantharajanN_0-1743148909949.png

 


Thanks & Regards,
Vasanth

Thanks @Vasantharajan N 

 

its helped me

@Aarushi1991 - Glad that I'm able to help you solve the issue. 


Thanks & Regards,
Vasanth

@Aarushi1991 

in quick messages you cannot call mail script but it should work in email

Let the actual email trigger and then check if email script prints the name, don't test in Preview

Response from ServiceNow employee below

AnkurBawiskar_0-1743148918004.png

 

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 ,

 

out of curiosity want to ask why its not showing in Preview email if everything is okay, Because all other mail script which i have written showing actual content in Preview email.

is there logic or something why its not showing ?