Why UI Action approval buttons (e.g. Approve/Reject) do not operate outside of workflow on a form?

rhett1
Tera Expert

I have a requirement to use the approve/reject feature on the grc_remediation table and the workflow works well.

However, the other requirement is to have the approval buttons (Approve/Reject) on the form itself, which I have created as UI Actions.   So far so good.   However, using the button script from Change, which is found below, it does not move the workflow forward when the button is used on the form itself.

current.approval = "approved";   //or rejected for the Reject button

current.update();

Can this be done?   If so, how?

1 ACCEPTED SOLUTION

Figured it out!



I created a UI Action for both Approve and Reject Form buttons and this was the code that moved the workflow forward:



current.approval = "approved";


//current.update();


var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('sysapproval', current.sys_id);
ap.query();


while(ap.next()){
ap.state = 'approved';
ap.update();
}


current.update();


View solution in original post

5 REPLIES 5

Mike Allen
Mega Sage

To get it to move the workflow that is already started for it, you will have to do some workflow scripting:



Workflow Script - ServiceNow Wiki


Thank you Mike for this link.   I have tried several of these scripts, including the one below, but to no resolution.  



var wf = new Workflow().getRunningFlows(current);


while(wf.next()) {    


    new Workflow().broadcastEvent(wf.sys_id, 'resume');


}



Any ideas of what can be used?


Figured it out!



I created a UI Action for both Approve and Reject Form buttons and this was the code that moved the workflow forward:



current.approval = "approved";


//current.update();


var ap = new GlideRecord('sysapproval_approver');
ap.addQuery('sysapproval', current.sys_id);
ap.query();


while(ap.next()){
ap.state = 'approved';
ap.update();
}


current.update();


brendanwilson84
Kilo Guru

HI Rhett,


Thanks for the UI action- Quite new to service now and I am having a problem



The workflow works for approve and reject.



find_real_file.png



However on my status it is saying completed


find_real_file.png




I would have hoped it showed like 'rejected'


find_real_file.png



This is the rejection UI action.


find_real_file.png



I was wondering if you had this issue?