I want current logged in user in the CC of the client script.

adityaverma
Tera Contributor

I tried adding current logged in user in Email client template in the CC as a recepeint "javascript: gs.getUser().getEmail()" but it wont work, can anyone help me on this?

3 ACCEPTED SOLUTIONS

Bhuvan
Tera Sage

@adityaverma 

 

Use below in email client template CC field,

 

https://www.servicenow.com/community/developer-forum/email-client-template-not-populating-cc/td-p/27...

 

https://www.servicenow.com/community/developer-forum/email-address-of-current-logged-in-user-not-pop...

 

javascript&colon; gs.getUserDisplayName() + " <" + gs.getUser().getEmail() + ">"

Bhuvan_0-1756997294590.png

Bhuvan_1-1756997553134.png

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan

View solution in original post

kaushal_snow
Mega Sage

Hi @adityaverma ,

 

Use a Client Email Template

In the CC field, enter:

 

javascript&colon; gs.getUserDisplayName() + " <" + gs.getUser().getEmail() + ">"


Alternate option: Use an Email Script for More Control....

 

If the above doesn’t meet your needs or doesn’t work consistently, use an Email Script instead....

Create a new script with the following structure:

(function runMailScript(/* GlideRecord */ current,
/* TemplatePrinter */ template,
/* Optional EmailOutbound */ email,
/* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.addAddress(
'cc',
gs.getUserDisplayName() + ' <' + gs.getUser().getEmail() + '>'
);
})(current, template, email, email_action, event);


In your Notification/ Email Trigger, reference this script in the message or body with:

${mail_script:your_script_name}

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/

View solution in original post

@adityaverma 

 

I provided the correct syntax along with screenshots and sample email notification using email client template in my earlier post.

 

If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

View solution in original post

13 REPLIES 13

Tried this as well did't worked.

@adityaverma 

 

Can you share screenshots of your email client template and sample record where you tried the template ?

 

Thanks,

Bhuvan

javascript&colon; gs.getUserDisplayName() + " <" + gs.getUser().getEmail() + ">" this worked for me but I am not getting why javascript&colon; gs.getUser().getEmail()  it is not working.

@adityaverma 

 

I provided the correct syntax along with screenshots and sample email notification using email client template in my earlier post.

 

If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan

kaushal_snow
Mega Sage

Hi @adityaverma ,

 

Use a Client Email Template

In the CC field, enter:

 

javascript&colon; gs.getUserDisplayName() + " <" + gs.getUser().getEmail() + ">"


Alternate option: Use an Email Script for More Control....

 

If the above doesn’t meet your needs or doesn’t work consistently, use an Email Script instead....

Create a new script with the following structure:

(function runMailScript(/* GlideRecord */ current,
/* TemplatePrinter */ template,
/* Optional EmailOutbound */ email,
/* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
email.addAddress(
'cc',
gs.getUserDisplayName() + ' <' + gs.getUser().getEmail() + '>'
);
})(current, template, email, email_action, event);


In your Notification/ Email Trigger, reference this script in the message or body with:

${mail_script:your_script_name}

 

If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.

 

 

Thanks and Regards,
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/