- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 10:25 AM
I'm writing a UI Action button on our Request form to allow some folks to cancel the request if necessary. Here is my action setup and script below:
function cancelrequest(){
current.request_state = 'closed_cancelled';
current.stage = 'closed_complete';
g_form.setVisible('comments', false);
current.update();
}
if (current.comments == '') {
alert('Please add the reason for the cancellation into the Additional Comments field.');
g_form.setVisible('comments',true);
g_form.isMandatory('comments', true);
return false;
}
else {
cancelrequest();
}
For some reason I keep getting the following error upon save:
Any ideas here on what I'm doing wrong? I was under the impression that doing a "return false;" aborted the action. What am I missing here?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 10:38 AM
It would look something like this. (Untested code - Please verify)
Action name: cancel_request
Onclick: cancelRequest();
Script:
//Client-side 'onclick' function
function cancelRequest(){
if(g_form.getValue('comments') == ''){
//Remove any existing field message, set comments mandatory, and show a new field message
g_form.hideFieldMsg('comments');
g_form.setMandatory('comments', true);
g_form.showFieldMsg('comments','Please add the reason for the cancellation into the Additional Comments field.','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'cancel_request'); //MUST call the 'Action name' set in this UI Action
}
//Code that runs without 'onclick'
//Ensure call to server-side function with no browser errors
if(typeof window == 'undefined')
serverCancel();
function serverCancel(){
//Set the correct values
current.request_state = 'closed_cancelled';
current.stage = 'closed_complete';
current.update();
gs.addInfoMessage('Request' + current.number + ' cancelled.'); //replace number with your desired field.
action.setRedirectURL(current);
}
P. S. Please hit like, helpful or correct for my responses as they apply to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 12:08 PM
That was half the battle. I had to edit the code to make the field visible.
Seems to be working now. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 12:11 PM
Glad you got it working.
P. S. Please hit like, helpful or correct for my responses as they apply to you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 12:10 PM
Please check my previous reply. Also, if the comments field is hidden, add this statement before line 6.
g_form.setVisible('comments', 'true');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2016 12:11 PM
I fixed that part. It's working now.
~ J ~
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-18-2016 06:02 PM
Thank you for indicating it's untested code!!