Email Client Template

BRUNO BANDEIRA
Tera Guru

Hello guys,

Could you help me with this problem!

I have the need to filter witch itens are gonna to appear in the 'TO' and 'CC' form in the compose email modal (That one that appears when you select 'Email' in the three dot button.

 

I have configured everything nicelly, and select the TAB Sender Configuration and select the SCRIPT option, using the snippet bellow:

 

(function(fromAddressQuery, targetRecord) {
    /**
     * fromAddressQuery: A GlideRecord on the table "sys_email_client_from_address".
     * targetRecord: A GlideRecord representing the record in which the Email Client was opened.
     */

    var recipients = {
        to: 'to_email@example.com',
        cc: 'cc_email@example.com'
    };

    // Log the values for debugging
    gs.info('To Field: ' + recipients.to);
    gs.info('CC Field: ' + recipients.cc);

    return recipients;
})(fromAddressQuery, targetRecord);
 
The log is showing that the execution of the script is running smoothly, but, nothing appears on both fields when the modal is open, TO and CC are empty.
 
What am I doing wrong?
2 ACCEPTED SOLUTIONS

Ahmmed Ali
Mega Sage

Hello @BRUNO BANDEIRA 

 

The script you have configured is for showing the from address for the email. If you want to configure the TO, CC and BCC dynamically, you will need to create a script include and call that script include in the respective field in recipient tab (the script function should return string of comma separated email IDs.

 

AhmmedAli_0-1735829278039.png

https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/administer/notification/t... 

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

View solution in original post

BRUNO BANDEIRA
Tera Guru

Thanks for your support @Ahmmed Ali and @Ankur Bawiskar this approach of javascript prefix did work for me!

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@BRUNO BANDEIRA 

where have you written the above script?

please share some screenshots

are you saying by default it should be set with that To and cc value?

if yes then you should set it here

AnkurBawiskar_0-1735828968145.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

Ahmmed Ali
Mega Sage

Hello @BRUNO BANDEIRA 

 

The script you have configured is for showing the from address for the email. If you want to configure the TO, CC and BCC dynamically, you will need to create a script include and call that script include in the respective field in recipient tab (the script function should return string of comma separated email IDs.

 

AhmmedAli_0-1735829278039.png

https://www.servicenow.com/docs/bundle/xanadu-platform-administration/page/administer/notification/t... 

 

Thank you,

Ali

 

If I could help you with your Query then, please hit the Thumb Icon and mark my answer as Correct!!

Thank you,
Ali

Hello @Ahmmed Ali 

I have the same issue even if I called the script include from "To" field of email client template it doesn't auto populate recipient list.

I can see its working with Washington and not in Yokohama. Any idea on it.

I have another suggestion. I have created a new field for the table with the type List and the reference is the user. I populate it with a script and then add the field name to the CC in the email client template. This is an issue with the fields To, CC, and BCC in the email client. You can only set one value for these fields with a script. If there are multiple values, nothing will appear.

Yaraslau_0-1747246313295.pngYaraslau_1-1747246538929.pngYaraslau_2-1747246623979.png

Please give me "Helpful"