- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-23-2016 10:56 PM
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!!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 07:46 AM
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.
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 :
- function referBack(){
- if (g_form.getValue('comments') == '') {
- // Remove any existing field message, set comments mandatory, and show a new field message
- try {
- g_form.hideFieldMsg('comments');
- } catch(e) {}
- g_form.setMandatory('comments', true);
- 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
- return false; // Abort submission
- }
- gsftSubmit(null, g_form.getFormElement(), 'refer_back'); // MUST call the 'Action name' set in this UI Action
- }
- // Code that runs without 'onclick'
- if (typeof window == 'undefined')
- serverReopen();
- function serverReopen() {
- var chg = new GlideRecord("change_request");
- chg.addQuery('sys_id' , current.getValue('sysapproval'));
- chg.query();
- if(chg.next())
- {
- chg.state = 1; //changing the state of change req back to 'Open' from 'Approval Requested'
- current.state = 'not requested'; // you might want to change the state of approval in the sysapproval_approver table from "requested" to "Not requested"
- }
- chg.update();
- current.update();
- gs.addInfoMessage(gs.getMessage("Request is referred back for changes")); // user friendly msg on success
- action.setRedirectURL(current);
- }
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 :
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?)
Happy working Anup. Please let me know your doubts if any.
Also please mark my answer correct if it fulfills your requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2016 07:46 AM
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.
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 :
- function referBack(){
- if (g_form.getValue('comments') == '') {
- // Remove any existing field message, set comments mandatory, and show a new field message
- try {
- g_form.hideFieldMsg('comments');
- } catch(e) {}
- g_form.setMandatory('comments', true);
- 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
- return false; // Abort submission
- }
- gsftSubmit(null, g_form.getFormElement(), 'refer_back'); // MUST call the 'Action name' set in this UI Action
- }
- // Code that runs without 'onclick'
- if (typeof window == 'undefined')
- serverReopen();
- function serverReopen() {
- var chg = new GlideRecord("change_request");
- chg.addQuery('sys_id' , current.getValue('sysapproval'));
- chg.query();
- if(chg.next())
- {
- chg.state = 1; //changing the state of change req back to 'Open' from 'Approval Requested'
- current.state = 'not requested'; // you might want to change the state of approval in the sysapproval_approver table from "requested" to "Not requested"
- }
- chg.update();
- current.update();
- gs.addInfoMessage(gs.getMessage("Request is referred back for changes")); // user friendly msg on success
- action.setRedirectURL(current);
- }
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 :
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?)
Happy working Anup. Please let me know your doubts if any.
Also please mark my answer correct if it fulfills your requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 06:33 AM
Thanks Arnab,
I have applied it and it is working fine.Really appreciate your help.
Thanks,
Anup
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-25-2016 06:39 AM
Thanks a lot for the recognition Anup !
Keep posting the community with such unique requirements.
Thanks,
Arnab