2/13/2018 email approval by email | ServiceNow Community
10 Replies · Latest reply on Sep 10, 2016 5:37 AM by Bhaskar Reddy
Bhaskar Reddy Sep 9, 2016 8:02 AM
email approval by email
This question is Not Answered.
Hi,
I have created one table Purchase Request, which is not extended from Task table.
I have created relationship of Purchase Request table with Approval table, mentioned query
with in that is: "current.addQuery("document_id", parent.sys_id)".
I have created one email notification to approve/reject request by Cost Center Manager, If I am
trying to approve request by email the status of my approval is not updating.
I have verified the details in System Mailboxes--->Outbound--->Skipped, in that email log
message is showing as: "Skipping 'Update Approval Request', did not create or update
sysapproval_approver".
Could you please help on this issue, As I am trying to resolve the issue, but i am not getting
what is the cause.
Please find the attached image for Approval record of my request:
Thanks & Regards,
Bhaskar Reddy
Approval Screen shot.PNG
17.2 K
I have the same question (0)
https://community.servicenow.com/message/1001032#1001032 1/12
2/13/2018 email approval by email | ServiceNow Community
1144 Views Tags:
1 HELPFUL
Arnab Dey Sep 9, 2016 10:07 AM (in response to Bhaskar Reddy)
Re: email approval by email
Hi Bhaskar,
We would definitely like help you.
Taking the 1st step, Could you please post the script in "Update Approval Request"? I believe this
will help us a lot.
Thanks,
Arnab
Actions Report Abuse Endorsers (0) Like (0)
Bhaskar Reddy Sep 9, 2016 8:32 PM (in response to Arnab Dey)
Re: email approval by email
Hi Arnab,
Thanks for your reply.
Inbound Action: "Update Approval Request", we are using out of box only.
Name Update Approval Request
Target table Approval [sysapproval_approver]
Type Reply
Condition
Script:
if (current.getTableName() == "sysapproval_approver") {
if (validUser()) {
gs.log("Parent ticket state--"+current.sysapproval.state,'Approval');
if(current.sysapproval.state==-5||current.sysapproval.state==1){
// if it's been cancelled, it's cancelled.
var doit;
if (current.state == 'cancelled')
doit = false;
https://community.servicenow.com/message/1001032#1001032 2/12
2/13/2018 email approval by email | ServiceNow Community
if(current.state=='requested'){
doit=true;
current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
if (email.body.state != undefined)
current.state = email.body.state;
if (email.subject.indexOf("approve") >= 0){
current.state = "approved";
if(current.sysapproval.sys_class_name == 'change_request'){
var change = new GlideRecord('change_request');
change.get('sys_id', current.sysapproval.sys_id);
if(current.group != ''){
var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.addQuery('sys_id', current.group);
groupApproval.addQuery('parent',change.sys_id);
groupApproval.query();
if(groupApproval.next()){
var indApproval = new GlideRecord('sysapproval_approver');
indApproval.addQuery('group', groupApproval.sys_id);
indApproval.addQuery('parent', change.sys_id);
indApproval.addQuery('sys_id', '!=', current.sys_id);
indApproval.query();
while(indApproval.next()){
indApproval.state = 'not_required';
indApproval.update();
}
groupApproval.approval = 'approved';
groupApproval.update();
}
}
change.comments=current.approver.name+' has provided the approval for this change.';
change.update();
}
var comments="Approved \n"+ebody;}
if (email.subject.indexOf("reject") >= 0){
current.state = "rejected";}
}
https://community.servicenow.com/message/1001032#1001032 3/12
2/13/2018 email approval by email | ServiceNow Community
if (doit){
current.update();
var table=current.sysapproval.sys_class_name;
//if(email.subject.indexOf("CHG") >= 0){table='change_request';}
if (email.subject.indexOf("reject") >= 0){
var gr=new GlideRecord(table);
gr.addQuery('sys_id',current.sysapproval.sys_id);
gr.query();
if(gr.next()){
var ebody='';
if(table=='change_request'){ebody=current.approver.name+' has Rejected the change.
\n';}
else{ebody='Rejected \n';}
ebody+=email.body_text.substring(0,email.body_text.indexOf(email.body.ref)-4);
gr.comments = ebody;
gr.update();}
}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") is already
cancelled or rejected");}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected
because Parent ticket state does not match with approval record");}
}
else {
gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected because
user sending email( "+email.from+") does not match the approver
("+current.approver.getDisplayValue()+")");
}
}
function validUser() {
if (current.approver == email.from_sys_id || gs.hasRole('admin'))
return true;
// check if the email is from a delegate of the approver
var g = new GlideRecord("sys_user_delegate");
g.addQuery("user", current.approver.toString());
g.addQuery("delegate", email.from_sys_id);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
https://community.servicenow.com/message/1001032#1001032 4/12
2/13/2018 email approval by email | ServiceNow Community
g.query();
return g.hasNext();
}
Actions Report Abuse Endorsers (0) Like (0)
Jose Valle Sep 9, 2016 10:10 AM (in response to Bhaskar Reddy)
Re: email approval by email
Hi Bhaskar,
You will see this message when the inbound action runs, but the script does not make use of
"current" update the record. You may want to review the logic in inbound action to see if
perhaps took a path in the code that does not actually update the record. Usually adding some
logging to the inbound action script can help out in figuring out which path it takes.
Are you using the out of the box "Update Approval Request" inbound action?
PS: Hit like, Helpful or Correct depending on the impact of the response
Actions Report Abuse Endorsers (0) Like (0)
Bhaskar Reddy Sep 9, 2016 8:34 PM (in response to Jose Valle)
Re: email approval by email
Hi Jose,
Thanks for your reply.
Inbound Action: "Update Approval Request", we are using out of box only.
Name Update Approval Request
Target table Approval [sysapproval_approver]
Type Reply
Condition
Script:
if (current.getTableName() == "sysapproval_approver") {
if (validUser()) {
gs.log("Parent ticket state--"+current.sysapproval.state,'Approval');
if(current.sysapproval.state==-5||current.sysapproval.state==1){
https://community.servicenow.com/message/1001032#1001032 5/12
2/13/2018 email approval by email | ServiceNow Community
// if it's been cancelled, it's cancelled.
var doit;
if (current.state == 'cancelled')
doit = false;
if(current.state=='requested'){
doit=true;
current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
if (email.body.state != undefined)
current.state = email.body.state;
if (email.subject.indexOf("approve") >= 0){
current.state = "approved";
if(current.sysapproval.sys_class_name == 'change_request'){
var change = new GlideRecord('change_request');
change.get('sys_id', current.sysapproval.sys_id);
if(current.group != ''){
var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.addQuery('sys_id', current.group);
groupApproval.addQuery('parent',change.sys_id);
groupApproval.query();
if(groupApproval.next()){
var indApproval = new GlideRecord('sysapproval_approver');
indApproval.addQuery('group', groupApproval.sys_id);
indApproval.addQuery('parent', change.sys_id);
indApproval.addQuery('sys_id', '!=', current.sys_id);
indApproval.query();
while(indApproval.next()){
indApproval.state = 'not_required';
indApproval.update();
}
groupApproval.approval = 'approved';
groupApproval.update();
}
}
change.comments=current.approver.name+' has provided the approval for this change.';
change.update();
}
var comments="Approved \n"+ebody;}
https://community.servicenow.com/message/1001032#1001032 6/12
2/13/2018 email approval by email | ServiceNow Community
if (email.subject.indexOf("reject") >= 0){
current.state = "rejected";}
}
if (doit){
current.update();
var table=current.sysapproval.sys_class_name;
//if(email.subject.indexOf("CHG") >= 0){table='change_request';}
if (email.subject.indexOf("reject") >= 0){
var gr=new GlideRecord(table);
gr.addQuery('sys_id',current.sysapproval.sys_id);
gr.query();
if(gr.next()){
var ebody='';
if(table=='change_request'){ebody=current.approver.name+' has Rejected the change.
\n';}
else{ebody='Rejected \n';}
ebody+=email.body_text.substring(0,email.body_text.indexOf(email.body.ref)-4);
gr.comments = ebody;
gr.update();}
}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") is already
cancelled or rejected");}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected
because Parent ticket state does not match with approval record");}
}
else {
gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected because
user sending email( "+email.from+") does not match the approver
("+current.approver.getDisplayValue()+")");
}
}
function validUser() {
if (current.approver == email.from_sys_id || gs.hasRole('admin'))
return true;
// check if the email is from a delegate of the approver
var g = new GlideRecord("sys_user_delegate");
https://community.servicenow.com/message/1001032#1001032 7/12
2/13/2018 email approval by email | ServiceNow Community
g.addQuery("user", current.approver.toString());
g.addQuery("delegate", email.from_sys_id);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
return g.hasNext();
}
Actions Report Abuse Endorsers (0) Like (0)
Kalaiarasan P Sep 10, 2016 12:04 AM (in response to Bhaskar Reddy)
Re: email approval by email
Please add the following lines to the inbound action and try
current.setForceUpdate(true);
current.update();
Actions Report Abuse Endorsers (0) Like (0)
Bhaskar Reddy Sep 10, 2016 12:12 AM (in response to Kalaiarasan P)
Re: email approval by email
Hi Kalaiarasan,
Thanks for your reply.
May I know where I can add
current.setForceUpdate(true);
current.update();
in my script.
Actions Report Abuse Endorsers (0) Like (0)
Kalaiarasan P Sep 10, 2016 12:17 AM (in response to Bhaskar Reddy)
Re: email approval by email
Before that, can you add the logs to your script and see where the script is failing
exactly?
https://community.servicenow.com/message/1001032#1001032 8/12
2/13/2018 email approval by email | ServiceNow Community
1 of 1 people found this helpful
Actions Report Abuse Endorsers (0) Like (0)
Bhaskar Reddy Sep 10, 2016 12:25 AM (in response to Kalaiarasan P)
Re: email approval by email
Hi Arnab,
Thanks for your reply.
Inbound Action: "Update Approval Request", we are using out of box only.
Name Update Approval Request
Target table Approval [sysapproval_approver]
Type Reply
Condition
Script:
if (current.getTableName() == "sysapproval_approver") {
if (validUser()) {
gs.log("Parent ticket state--"+current.sysapproval.state,'Approval');
if(current.sysapproval.state==-5||current.sysapproval.state==1){
// if it's been cancelled, it's cancelled.
var doit;
if (current.state == 'cancelled')
doit = false;
if(current.state=='requested'){
doit=true;
current.comments = "reply from: " + email.from + "\n\n" + email.body_text;
if (email.body.state != undefined)
current.state = email.body.state;
if (email.subject.indexOf("approve") >= 0){
current.state = "approved";
if(current.sysapproval.sys_class_name == 'change_request'){
var change = new GlideRecord('change_request');
change.get('sys_id', current.sysapproval.sys_id);
https://community.servicenow.com/message/1001032#1001032 9/12
2/13/2018 email approval by email | ServiceNow Community
if(current.group != ''){
var groupApproval = new GlideRecord('sysapproval_group');
groupApproval.addQuery('sys_id', current.group);
groupApproval.addQuery('parent',change.sys_id);
groupApproval.query();
if(groupApproval.next()){
var indApproval = new GlideRecord('sysapproval_approver');
indApproval.addQuery('group', groupApproval.sys_id);
indApproval.addQuery('parent', change.sys_id);
indApproval.addQuery('sys_id', '!=', current.sys_id);
indApproval.query();
while(indApproval.next()){
indApproval.state = 'not_required';
indApproval.update();
}
groupApproval.approval = 'approved';
groupApproval.update();
}
}
change.comments=current.approver.name+' has provided the approval for this
change.';
change.update();
}
var comments="Approved \n"+ebody;}
if (email.subject.indexOf("reject") >= 0){
current.state = "rejected";}
}
if (doit){
current.update();
var table=current.sysapproval.sys_class_name;
//if(email.subject.indexOf("CHG") >= 0){table='change_request';}
if (email.subject.indexOf("reject") >= 0){
var gr=new GlideRecord(table);
gr.addQuery('sys_id',current.sysapproval.sys_id);
gr.query();
if(gr.next()){
var ebody='';
if(table=='change_request'){ebody=current.approver.name+' has Rejected the
change. \n';}
else{ebody='Rejected \n';}
https://community.servicenow.com/message/1001032#1001032 10/12
2/13/2018 email approval by email | ServiceNow Community
ebody+=email.body_text.substring(0,email.body_text.indexOf(email.body.ref)-4);
gr.comments = ebody;
gr.update();}
}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") is
already cancelled or rejected");}
}
else{gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+")
rejected because Parent ticket state does not match with approval record");}
}
else {
gs.log("Approval for task ("+current.sysapproval.getDisplayValue()+") rejected
because user sending email( "+email.from+") does not match the approver
("+current.approver.getDisplayValue()+")");
}
}
function validUser() {
if (current.approver == email.from_sys_id || gs.hasRole('admin'))
return true;
// check if the email is from a delegate of the approver
var g = new GlideRecord("sys_user_delegate");
g.addQuery("user", current.approver.toString());
g.addQuery("delegate", email.from_sys_id);
g.addQuery("approvals", "true");
g.addQuery("starts", "<=", gs.daysAgo(0));
g.addQuery("ends", ">=", gs.daysAgo(0));
g.query();
return g.hasNext();
}
Actions Report Abuse Endorsers (0) Like (0)
Kalaiarasan P Sep 10, 2016 12:30 AM (in response to Bhaskar Reddy)
Re: email approval by email
So if you see the code, its getting driven by sysapproval field which will work for
task based tables. Since your table is not extended from task, the code might
not work for you.
https://community.servicenow.com/message/1001032#1001032 11/12
2/13/2018 email approval by email | ServiceNow Community
I would suggest to add logs to the script and check where the script is exactly
failing and add the code to use document ID and table name field if it is a non
task based approval.
Actions Report Abuse Endorsers (0) Like (0)
Bhaskar Reddy Sep 10, 2016 5:37 AM (in response to Kalaiarasan P)
Re: email approval by email
Can you please explain me, where I should add logs to my script.
Actions Report Abuse Endorsers (0) Like (0)
Copyright © 2018 ServiceNow. All rights reserved.
Help | Contact Us
Terms of Use | Privacy Statement | Trademarks
https://community.servicenow.com/message/1001032#1001032 12/12