- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 03:55 PM
Hello,
Kinda stuck on this and tired of beating my head against this particular wall. There are plenty of other walls in need of head-pounding.
I need to make categories and subcategories mandatory on a UI Action called Escalate. I want the button to show up, but if cat/subcat are empty, it should 1) throw an error message, 2) make the fields mandatory, and 3) flash the fields red. The cat/subcats available on the form are controlled by another field called u_platform via a UI Policy (which works).
I'm trying to have the UI Action check the u_platform, and then make the appropriate cat/subcats mandatory. It partially works, but won't abort or redirect to current when I am using g_form. Can anyone tell me what I'm doing wrong?
Here's the script:
if (current.u_platform == 'Platform1'){
if (current.u_subcategory_task.nil()) {
gs.addErrorMessage(gs.getMessage("Category and Subcategory are required to Escalate"));
g_form.setMandatory('u_category_task', true);
g_form.setMandatory('u_subcategory_task', true);
g_form.flash("case.u_category_task", "red", 0);
g_form.flash("case.u_subcategory_task", "red", 0);
action.setRedirectURL(current);
current.setAbortAction(true);
}}
What happens is it submits and returns to the List (ignoring the setRedirectURL and setAbortAction. While on the list, you see the error message (which means the if statements are returning true properly), and when you reopen the ticket, the fields are now mandatory. I'm guessing they flashed red, but wasn't seen as we were kicked back to the list.
If I remark out the g_form lines, the redirect and abort work. So g_form and the other actions don't play well together. Isn't everything in this script client side?
So what's the problem?
Any help would be greatly appreciated.
Thank you,
Robert
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 05:24 PM
Hi Robert,
As the Leader @pradeepksharma mentioned , Your script might need little bit of clean ups(I guess, same applies to the wall that your beating head against, )
I havenot tested below code, just modified your script here,
function callMeToSeeMyPower() {
if (g_form.getValue('u_platform') == 'Platform1'){
if (g_form.getValue('u_subcategory_task') == '') {
g_form.addErrorMessage(getMessage("Category and Subcategory are required to Escalate"));
g_form.setMandatory('u_category_task', true);
g_form.setMandatory('u_subcategory_task', true);
g_form.flash("case.u_category_task", "red", 0);
g_form.flash("case.u_subcategory_task", "red", 0);
return false;
}}
}
Also, make sure to enable client check box enabled on your ui action and paste callMeToSeeMyPower() on Onclick field.
Let us know,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 04:04 PM
Hello Robert,
I see client and server code as part of your script. Please adjust the code by following instructions from the below blog.
https://www.servicenowguru.com/system-ui/ui-actions-system-ui/client-server-code-ui-action/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-01-2017 05:24 PM
Hi Robert,
As the Leader @pradeepksharma mentioned , Your script might need little bit of clean ups(I guess, same applies to the wall that your beating head against, )
I havenot tested below code, just modified your script here,
function callMeToSeeMyPower() {
if (g_form.getValue('u_platform') == 'Platform1'){
if (g_form.getValue('u_subcategory_task') == '') {
g_form.addErrorMessage(getMessage("Category and Subcategory are required to Escalate"));
g_form.setMandatory('u_category_task', true);
g_form.setMandatory('u_subcategory_task', true);
g_form.flash("case.u_category_task", "red", 0);
g_form.flash("case.u_subcategory_task", "red", 0);
return false;
}}
}
Also, make sure to enable client check box enabled on your ui action and paste callMeToSeeMyPower() on Onclick field.
Let us know,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 10:21 AM
Hi Srinivas,
I was originally wrapping it in a function was using all g_form, but having trouble, so I started "simplifying" to try to figure out what was wrong. After testing your solution, I didn't think it worked either.
However, there was an aspect to this that I didn't outline because I thought it would be a distraction - which is that the UI Action calls a state flow, and the script is run from the state flow. When I do exactly as you say in the UI Action, this works.
I think I should do this as a Client Script given the above.
Thanks,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-18-2023 07:11 AM
UI Action
Onclick: setM();
function setM() { var c = 0; var arr = ['fieldname1','fieldname2','variables.variablename1','variables.variablename2']; for (var i = 0; i < arr.length; i++) { if (g_form.getValue(arr[i]) == '') { g_form.setMandatory(arr[i], true); c++; } } if (c>0){ alert('Please fill Mandatory fields'); } var mrvs = g_form.getValue('mrvs_name'); var data = JSON.parse(mrvs); if (data.length == 0) { alert('MRVS cannot be empty!'); } if (c == 0 && data.length > 0) { g_form.setValue('state', 'submit'); g_form.save(); } }