Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Resend email

shaik23
Tera Expert

Hi all,

i am having requirement to resend emails for approvals using ui action 

i have a script i need suggestion 

 

resendThisApproval();
action.setRedirectURL(current.sysapproval)

function resendThisApproval() {
   var e = new GlideRecord("sys_email");
   e.addQuery("type", "sent");
   e.addQuery("target_table", current.getTableName());
   e.addQuery("instance", current.sys_id);
   e.orderByDesc("sys_created_on");
   e.setLimit(1);
   e.query();
 
   if (e.next()) {
      e.mailbox = "outbox";
      e.type = "send-ready";
      if (e.update()) {
         gs.addInfoMessage("Resent: " + e.subject);
      } else {
         gs.addErrorMessage("Could not resend: " + e.subject);
      }
   } else {
      gs.addErrorMessage("Approval email not found for " + current.approver.name + " / " + current.sysapproval.number);
   }
}
1 ACCEPTED SOLUTION

Hi @shaik23 

If your issue has been solved please mark my answer as Accepted Solution.

 

You cant see updated email in email logs because you might be seraching with the wrong query. please open sys_email.LIST and Target as sys_id of the approval record

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,
Piyush Sain

View solution in original post

13 REPLIES 13

shaik23
Tera Expert

@Sandeep Rajput  i am getting this error when the script executes 

shaik23_0-1704888810026.png

 

@shaik23 Looks like the glide query you are using to fetch the record is not returning any result. Could you please post the updated script here?

@Sandeep Rajput  That is the script i have

@shaik23 

 var e = new GlideRecord("sys_email");
   e.addQuery("type", "sent");
   e.addQuery("target_table", current.getTableName());
   e.addQuery("instance", current.sys_id);
   e.orderByDesc("sys_created_on");
   e.setLimit(1);
   e.query();

Looks like this query is not returning any result. I recommend running this script as a background script by replacing current.getTableName() with table name and current.sys_id with the sys_id in consideration and check if the query returns anything.

shaik23_0-1704889392163.png

the target table is approval