mail script to get requested for from request into sysapproval_approver notification

Community Alums
Not applicable

Trying to use a mail script inside the body of a notification called 'Catalog Approval Rejected' that runs off the sysapproval_approver table. In the 'Who will receive' I have Approver and 'Approver.Opened by' but I also need the Requested For, which isn't available in the 'Users/Groups in fields' picker. I've been on the other forums where someone needed this also and have tried to copy bits and pieces from the Accepted Solutions to fit my own needs, but it's still not sending the notification to the requested for. Where in this mail script am I doing something wrong, please? 

find_real_file.png

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

You should be able to simply use something like:

var userEmail = current.document_id.request.requested_for.email;
var userName = current.document_id.request.requested_for.name;
email.addAddress("cc", userEmail, userName);

This is assuming that your notification is using the sysapproval_approver table.

Then simply use this in your email notification content:

${mail_script:name_of_mail_script}

Otherwise, if you still need to use your script or would like to, simply change your addQuery regarding the sys_id to this:

user.addQuery('sys_id', current.document_id.request.requested_for.sys_id);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

You should be able to simply use something like:

var userEmail = current.document_id.request.requested_for.email;
var userName = current.document_id.request.requested_for.name;
email.addAddress("cc", userEmail, userName);

This is assuming that your notification is using the sysapproval_approver table.

Then simply use this in your email notification content:

${mail_script:name_of_mail_script}

Otherwise, if you still need to use your script or would like to, simply change your addQuery regarding the sys_id to this:

user.addQuery('sys_id', current.document_id.request.requested_for.sys_id);

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Community Alums
Not applicable

Ok so here is the mail script now

find_real_file.png

and here is the notification body - the script is called at the end (highlighted in blue) find_real_file.png

 

... but when I reject a RITM, only the people listed in 'Who will receive' tab of the notification are getting an email; still not the Requested For. What else am I missing? 

Community Alums
Not applicable

I found an error. Is something wrong with how I'm putting together the email address? 

find_real_file.png

Hi,

The script I provided works, so it's something with the email address listed for this user that you all have blocked?

Check your system email address filters:

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/administer/notification/concept/sy...

https://docs.servicenow.com/bundle/paris-servicenow-platform/page/administer/notification/task/set-e...

Something you all have set is blocking the email address from being added to send, you all are blocking that domain it seems.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!