- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:20 AM
Morning All -
I am working on a custom application that generates approval records via workflow. What I would like to do is have Approve and Reject buttons on my custom table that updates the state field in the sysapproval_approver table.
To that end I have made a UI Action with this code:
var currentRec = current.getValue('number');
var gr = new GlideRecord('sys_approval_approver');
gr.addQuery('approval_for',currentRec);
gr.query();
while (gr.next()) {
gr.state = 'approved';
}
gr.update();
and it is not working. I also had currentRec set like this:
var currentRec = current.sys_id;
and it did not work with that either.
So I guess I'm confused about which field I should be querying for in the Approval table and what I should be passing into it.
Guidance on this issue would be appreciated.
Thanks!
Chris
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:25 AM
Hi Chris,
Try something more like this:
var currentRec = current.sys_id;
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',currentRec);
gr.addQuery('state', 'requested');
gr.query();
while (gr.next()) {
gr.state = 'approved';
gr.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:22 AM
The name of the table is sysapproval_approver. Try this.
var currentRec = current.getValue('sys_id');
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('approval_for',currentRec);
gr.query();
while (gr.next()) {
gr.state = 'approved';
}
gr.update();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:25 AM
Hi Chris,
Try something more like this:
var currentRec = current.sys_id;
var gr = new GlideRecord('sysapproval_approver');
gr.addQuery('sysapproval',currentRec);
gr.addQuery('state', 'requested');
gr.query();
while (gr.next()) {
gr.state = 'approved';
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:32 AM
Thanks guys - much appreciated!
Brad's example worked - to some extent. It updated the state field like I wanted, but instead of sending the request on to the next person in line, it generated another approval for the same person that just approved it.
Does some other field need to be changed in order for my workflow to actually recognize that an approval has taken place?
This is a new behavior I've not seen as yet.... I'm confused.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-25-2016 06:37 AM
It should work the same way as if someone approved it manually. Have you tested approving it manually and seeing if it does that? Posting a screenshot of the workflow and approval activity definition could help as well.