Rollback state using UI action

anup4253
Kilo Contributor

Hi everyone,

I need to create a UI action which changes my state backward on my   approval form.

eg. if the state is Authorize it should change it to New.

How to achieve it?

please describe!!

1 ACCEPTED SOLUTION

Hi Anup,



I could write down a UI action code for you which on click would satisfy your requirements (I had the code tested fully, works fine):



Since the approver will initiate the process so we need to make the Button on Approval [sysapproval_approver] table.


refer.PNG


In the "Condition" field you can give your own condition according to convenience.


I have done this for a change request approval.


The code below :



  1. function referBack(){
  2.   if (g_form.getValue('comments') == '') {
  3.   // Remove any existing field message, set comments mandatory, and show a new field message
  4.   try {
  5.   g_form.hideFieldMsg('comments');
  6.   } catch(e) {}
  7.   g_form.setMandatory('comments', true);
  8.   g_form.showFieldMsg('comments', getMessage('Please enter a comment why would you like to refer back'), 'error'); // If you want the approver to describe the changes he needs
  9.   return false;   // Abort submission
  10.   }
  11.   gsftSubmit(null, g_form.getFormElement(), 'refer_back'); // MUST call the 'Action name' set in this UI Action
  12. }
  13. // Code that runs without 'onclick'
  14. if (typeof window == 'undefined')
  15.   serverReopen();
  16. function serverReopen() {
  17.   var chg = new GlideRecord("change_request");
  18.   chg.addQuery('sys_id' , current.getValue('sysapproval'));
  19.   chg.query();
  20.   if(chg.next())
  21.   {
  22.   chg.state = 1; //changing the state of change req back to 'Open' from 'Approval Requested'
  23.   current.state = 'not requested'; // you might want to change the state of approval in the sysapproval_approver table from "requested" to "Not requested"
  24.   }
  25.   chg.update();
  26.   current.update();
  27.   gs.addInfoMessage(gs.getMessage("Request is referred back for changes")); // user friendly msg on success
  28.   action.setRedirectURL(current);
  29. }


Copy paste this code and do your necessary changes.


Below screenshot shows error msg when approver tries to click on Refer Back button without any comments :


refer1.PNG


Below screenshot shows success msg and changes the state to not yet requested :


You can also notice that the "Refer Back" button is gone since it is already referred.(we don't need the button now. Do we?)


refer2.PNG


Happy working Anup. Please let me know your doubts if any.


Also please mark my answer correct if it fulfills your requirement


View solution in original post

12 REPLIES 12

arnabwa
Giga Guru

Hi Anup,



Could you please let us know on what conditions do you want to change back the approval? This is just for my understanding. Please elaborate !




Thanks,


Arnab


anup4253
Kilo Contributor

Hi Arnab,



The condition is simple.For ex-> Suppose an approval is triggered   when my change moves from access to Authorize state.


The approver before approving finds that some fields needs to corrected or certain changes needs to be done on the form. So, he clicks the button (Refer Back....the UI action which I need) which directs him back to the New state of the form and then the user sets in new values or does the rectification as required.



The UI action(button) when clicked should trigger a notification simultaneously, which will inform the user that certain changes needs to be done.



Thanks,


Anup


Hi Anup



I feel this can be done via Workflow, the user should reject the Change and on Rejection you can roll back(use the activity) the change to earlier stage.



Regards


Avinash


Hi Avinash,



Yes it could be achieved through workflow.


But there a business requirement that this button should be visible on the approval form for referring back.



Thanks,


Anup