Professional Documents
Culture Documents
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:
https://community.servicenow.com/message/1001032#1001032 1/12
2/13/2018 email approval by email | ServiceNow Community
1 HELPFUL
Hi Bhaskar,
Thanks,
Arnab
Hi Arnab,
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 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(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 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;
https://community.servicenow.com/message/1001032#1001032 4/12
2/13/2018 email approval by email | ServiceNow Community
g.query();
return g.hasNext();
}
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
Hi Jose,
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(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(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 (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;
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();
}
Please add the following lines to the inbound action and try
current.setForceUpdate(true);
current.update();
Hi Kalaiarasan,
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
Hi Arnab,
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(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;
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 (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;
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.
Can you please explain me, where I should add logs to my script.
https://community.servicenow.com/message/1001032#1001032 12/12