UI Action button for Approve on a form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 09:24 AM
Hi All,
I have a requirement to add an Approve button to a form. The records related to this form require an approval from two users before the approval state moves to approved. I have added a UI Action to create the Approval button on the form with the following script:
action.setRedirectURL(current);
current.update();
updateRecord();
function updateRecord(){
var rec = new GlideRecord('sysapproval_approver');
rec.addQuery('sysapproval', current.sys_id).addOrCondition('document_id', current.sys_id);
rec.query();
if(rec.next()){
rec.state = 'approved';
rec.update();
}
}
The approval button works fine for the first user that approves but when the second user approves the approval state for the second user does not update and remains in a Requested state.
If anyone has an idea why this is happening and how to resolve it I would be very appreciative!
Regards,
Ross
- Labels:
-
User Interface (UI)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 09:45 AM
Hi,
When it runs first time state is already approved right? before the second approver approves
or am i missing something
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 09:49 AM
Hi Yousaf,
The flow requires approval from all approvers before the state of the record moves to approved. So currently when the first approver approvers via the button the state or their approval request moves to approved, but when the second approver approves via the button the state of their approval remains "Requested".
So the Approve button is only working as desired for the first approver that approves.
Does that make sense?
Ross

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2022 10:13 AM
Yes thanks that what I think is the problem after the first approver approves it shouldn't change it to approve. Because if its already approved whats the point of approving of second approver.
I don't think UI Action is a good way to handle this
***Mark Correct or Helpful if it helps.***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-17-2024 01:20 AM
Hi Yousaf,
Just add another filter as below and boom.