Inbound Email Action for Approving / rejecting the request through email
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2019 04:47 AM
Hi All,
I have one requirement for approving or rejecting the requests by replying through email.
I have inbound action to perform this action. My issue is whenever i am replying with the keyword rejected/reject the request is getting approved in system.
Can someone help me to understand this.
My Code is,
*****************************************************************************
if (current.getTableName() == "sysapproval_approver") {
if (validUser()) {
current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
// if it's been cancelled, it's cancelled.
var doit = true;
if (current.state=='cancelled'){
doit = false;
}
if (email.body.state != undefined){
current.state = email.body.state;
}
//if email body or email subject contains "Approve" or "Reject" corresponding action will be taken
var elast=email.body_text.indexOf("reply to this email: ");
var ereply=email.body_text.slice(0,elast);
var esubj=email.subject.toLowerCase();
var ebody=ereply.toLowerCase();
gs.log(esubj.indexOf("approved")>=0 +current.sysapproval.getDisplayValue()+"Subject Vignesh");
gs.log(ebody.indexOf("approved")>=0 +current.sysapproval.getDisplayValue()+"body value");
if (esubj.indexOf("approved") >=0 || ebody.indexOf("approved")>=0){
current.state = "approved";
gs.log("approved");
}
else if (esubj.indexOf("rejected")>=0 || ebody.indexOf("rejected")>=0){
current.state = "rejected";
gs.log("rejected");
}
gs.log("Final state "+ current.state);
gs.log("ebody "+ ebody);
if (doit)
{
current.update();
}
} else {
gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected because user sending email( "+email.from+") does not match the approver ("+current.approver.getDisplayValue()+")");
}
}
*************************************************************************************************
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-16-2019 05:17 AM
Approvals and rejection email actions are available OOB. There are two - one for approval and one for rejection. They are keyed off the subject line, not the email body content which can be ambiguous.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2021 04:17 AM
Hi Chuck,
The OOB inbound action "Update Approval Request" works with email body having "State: Approved" only and for Approving only.
The same does not work for rejection or the OOB code does not work with only subject having keywords "approved" or "rejected"
Could you please send code if you have any working /updated OOB approval for above issues.?
Thank you,
Sumana