Approval UI Action on Custom UI Page

Matthew Glenn
Kilo Sage

Hey all,

 

Out of necessity, I recently had to create a custom mobile UI Page for to use for approvals. I have everything working to management's specifications with one small exception, the actual approvals actions.

 

My question is, how can I get behavior similar to that of a UI Action on a custom HTML button, specifically the 'Approve' and 'Reject' UI Actions from the sysapproval_approver table?

 

Can anyone assist?

 

 

If you're at all curious as to why I'm going this route, please see Display Issue With Mobile Approvals

1 ACCEPTED SOLUTION

I got this working for the most part. Below is what I have for the Client Script (in case you're curious). Thank you for your help!!



function apr() {


  var approval = new GlideRecord('sysapproval_approver');


  approval.addQuery('sys_id','=','$[jvar_approval_sysid]');


  approval.addQuery('status','=','requested');


  approval.query();


  while(approval.next()) {


            approval.state = 'approved';                                                             //set approval to 'approved'


            approval.update();                                                                                 //update approval


            var record = new GlideRecord('u_invoices');


            record.addQuery('sys_id','=','$[app.document_id.sys_id]'); //(from UI Page contents)


            record.query();


            while(record.next()){


                      record.update();                                                                         //update record


            }


  }


}


View solution in original post

4 REPLIES 4

Kalaiarasan Pus
Giga Sage

did you try?



pass the sys id of the record to be approved/rejected on click of the button to a function in 'client script' section.... use glide ajax and query and get the record in script include... update the state of the record to approved/rejected as required....


Yes, I did try. I should have included all this in the original post.



Here is what I have:



In the body of the UI Page, I set '$[jvar_approval_sysid]' as the sys_id of the approval.



Then I have a standard HTML button that calls a function listed in the Client Script section:



<input type="button" value="Approve" onclick="apr()"></input>



Here is that function, with '$[jvar_approval_sysid]' in the query:



function apr() {


  alert('This will approve $[jvar_approval_sysid]');     //alert for me


  var approval = new GlideRecord('sysapproval_approver');


  approval.addQuery('sys_id','=','$[jvar_approval_sysid]');


  approval.query();


  while(approval.next()) {


          approval.state = 'approved';


          approval.document_id.status = 'Approved';


          approval.update();


  }


}



The variable '$[jvar_approval_sysid]' does, in fact, return the sys_id of the approval that I'm currently working on.



Now, with all this in place, the approval is changing status to 'approved' (or rejected). However, whatever happens behind the scenes that would normally change the status of the item associated with the approval is not happening. The status is staying the same.



I'm thinking Line 8 is where the problem may lie, as the document_id (associated record) is what is not being updated. Either that, or I am way off target here.



Any additional help is appreciated.


line 8 is wrong i guess...



field name must be sysapproval if am not wrong.... are you trying to update something on the record related to approval?


I got this working for the most part. Below is what I have for the Client Script (in case you're curious). Thank you for your help!!



function apr() {


  var approval = new GlideRecord('sysapproval_approver');


  approval.addQuery('sys_id','=','$[jvar_approval_sysid]');


  approval.addQuery('status','=','requested');


  approval.query();


  while(approval.next()) {


            approval.state = 'approved';                                                             //set approval to 'approved'


            approval.update();                                                                                 //update approval


            var record = new GlideRecord('u_invoices');


            record.addQuery('sys_id','=','$[app.document_id.sys_id]'); //(from UI Page contents)


            record.query();


            while(record.next()){


                      record.update();                                                                         //update record


            }


  }


}