We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Include Email Script in "sysapproval" hyperlink

Erik Nelson
Mega Sage

Hello!

I'm working on a notification for a rejected approval, and have been asked to include a link back to the record that was rejected. This normally would be pretty straightforward, but what I'm up against is this is a custom App (extended from Task) and we only want the records interacted with in their own Workspace. I do have an email script that builds the URL so that a notification like "Task assigned to your group" takes them into the workspace, but I have no idea how to effectively do this from the Approvals table. I'm doing the notification from there because we want to include the comments from the rejection in the notification. Any assistance or suggestions are greatly appreciated.


Thanks,

Erik

1 ACCEPTED SOLUTION

vaishali231
Kilo Sage

Hey @Erik Nelson 

Since the notification is being triggered from sysapproval_approver, you can still generate a Workspace link to the rejected record by using the sysapproval reference field. That field points to the record that was approved/rejected, so you can retrieve the target record and build the Workspace URL dynamically.

Create an Email Script and use something similar to the following:

(function runMailScript(current, template, email, email_action, event) {

   var targetRecord = current.sysapproval.getRefRecord();

   if (!targetRecord || !targetRecord.isValidRecord()) {
       template.print("Unable to generate record link.");
       return;
   }
   var baseUrl = gs.getProperty('glide.servlet.uri');

   // Update the workspace name/path to match your environment
   var workspaceUrl = baseUrl +
       'now/workspace/my_workspace/record/' +
       targetRecord.getTableName() + '/' +
       targetRecord.getUniqueValue();

   template.print(
       '<a href="' + workspaceUrl + '">Open Rejected Record</a>'

   );

})(current, template, email, email_action, event);

Then reference the Email Script in your notification:

${mail_script:workspace_link}

*************************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh

Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb




View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron

@Erik Nelson 

share screenshots and also the email script

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

vaishali231
Kilo Sage

Hey @Erik Nelson 

Since the notification is being triggered from sysapproval_approver, you can still generate a Workspace link to the rejected record by using the sysapproval reference field. That field points to the record that was approved/rejected, so you can retrieve the target record and build the Workspace URL dynamically.

Create an Email Script and use something similar to the following:

(function runMailScript(current, template, email, email_action, event) {

   var targetRecord = current.sysapproval.getRefRecord();

   if (!targetRecord || !targetRecord.isValidRecord()) {
       template.print("Unable to generate record link.");
       return;
   }
   var baseUrl = gs.getProperty('glide.servlet.uri');

   // Update the workspace name/path to match your environment
   var workspaceUrl = baseUrl +
       'now/workspace/my_workspace/record/' +
       targetRecord.getTableName() + '/' +
       targetRecord.getUniqueValue();

   template.print(
       '<a href="' + workspaceUrl + '">Open Rejected Record</a>'

   );

})(current, template, email, email_action, event);

Then reference the Email Script in your notification:

${mail_script:workspace_link}

*************************************************************************************************************************************

If this response helps, please mark it as Accept as Solution and Helpful.

Doing so helps others in the community and encourages me to keep contributing.

Regards

Vaishali Singh

Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb




Erik Nelson
Mega Sage

Thank you! I had the original setup in place for creating the link, just didn't know how to extend it for approvals.