- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 02:02 AM
Hi SNC,
I am trying to set up a use case where when a user tries to close a catalog task, he has to enter customer comment notes.
For the action of closing the catalog task I have an UI Action button on the catalog task form, which has the following code:
current.task_state = 3;
current.update();
For the user comments field I am using the customer comments field from the RITM.
And for the script I wrote, it's on the catalog task table, and it looks like this:
So at first sight it all seems OK, but if I change the state from the drop down list. However, when I try to click the UI button, it does not work. It just closes the task without prompting me for anything.
Any ideas where am I going wrong?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 02:11 AM
Add this code to your ui action
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','Comments are mandatory','error');
return false; //Abort submission
}
Use the ui action that has both client anbd server side code. this will be client side code, and
current.task_state = 3;
current.update();
this will be your server side code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 04:45 AM
Actually request_item.comments was the field that does the work for me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 02:11 AM
Add this code to your ui action
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','Comments are mandatory','error');
return false; //Abort submission
}
Use the ui action that has both client anbd server side code. this will be client side code, and
current.task_state = 3;
current.update();
this will be your server side code.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 02:16 AM
Hi Dimit,
Your changing the state by clicking the Ui button in that case client script wont ask for any mandatory fields.
select check box "Client" and Write the code in uiaction .
alert('Please leave comments why are you setting state to completed');
g_form.setMandatory('request_item.comments', true);
For more informatio nclick this link http://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
Regards,
Harish.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2014 04:45 AM
I managed to get it all into the UI Action - both client and server side code. Thanks to all for the quick replies!