Make comments mandatory on click of a ui action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 06:15 AM
Good Afternoon everyone,
I currently have an issue where I need to make the comments field on the sys_approval table mandatory when a user is rejecting a change. This would work by the user clicking on the reject ui action and then it would not let them reject the change until a comment has been put into the comments field. Has anybody done this before?
Thanks,
Luke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 06:32 AM
I had a similar requirement and below is UI Action code that should work. I based this off of the out of the box code for the Resolve Incident UI Action since it behaves in a similar manner.
- Personalize the Reject UI Action - the Form Button, not the list action
- Change the action name to "reject_approval" - this needs to be changed because action name needs to be unique for the code below and there are many out of the box UI Actions with an action name of "reject".
- Check the Client Checkbox
- Set the OnClick value to rejectApproval();
- Leave the condition as it is
- Replace the script with the code below. Feel free to edit the error messages in the code.
function rejectApproval(){
g_form.setValue('state', 'rejected');
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','Reason is required when rejecting a Change','error');
return false; //Abort submission
}
//Call the UI Action and skip the 'onclick' function
gsftSubmit(null, g_form.getFormElement(), 'reject_approval'); //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')
serverReject();
function serverReject(){
current.state = 'rejected';
current.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:04 AM
Hi Everyone,
Thanks for your thoughts on this. I've tried Michael's method and in the main this works. The only issue is that it is not changing the state to rejected after comments are entered and the reject ui action button has been clicked. Any thoughts?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:13 AM
make sure that in the above code line#12
gsftSubmit(null, g_form.getFormElement(), 'reject_approval');
you call the correct action name, for Michael it maybe reject_approval, for you it might be "reject". Just take a look at the Action Name for your reject button and replace this with that
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:16 AM
This works for me, I am on Eureka Patch 1 and have another instance on Patch 5. Can you please provide exact step by step to recreate?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2014 07:22 AM
Brilliant. I've got it working now Harikrishan was right i hadn't changed the action name to the 'reject approval'. Now updated it and it works.
Many Thanks,
Luke