- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2017 06:27 AM
Hi All
I am trying to write UI Action script for below scenario:
when Demand manager go to an existing demand that is in draft status and do NOT fill in any/all of the below fields and click on"Submit demand" button then there should be an error message that reads "The following mandatory fields are not filled in : <field name1> , <field name2>":
Business Unit
Primary Queue
Value Driver
Proposed Start Year
I have written UI Action as:
Table: IT Demand [tsp1_demand]
Active: True
Show update: True
Onclick: checkRequired()
Client: True
Condition: current.state==1 && gs.hasRole('demand_manager')
Script:
function checkRequired() {
var bunit = g_form.getValue('u_portfolio_bu');
var pqueue = g_form.getValue('u_primary_queue');
var vdriver = g_form.getValue('u_initiative');
var psuser = g_form.getValue('u_start_year');}
if (bunit == '' && pqueue == '' && vdriver == '' && puser == '') {
g_form.setMandatory('u_portfolio_bu', true);
g_form.setMandatory('u_primary_queue', true);
g_form.setMandatory('u_initiative', true);
g_form.setMandatory('u_start_year', true);
g_form.showFieldMsg('u_portfolio_bu','u_primary_queue','u_initiative', 'u_start_year','is required to submit.', 'error');
}
Above script is not working, user is able to Sumbit demand and there is no error message.
This is the first time I am writing script, please help me in correcting this script.
Thanks and Regards
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 12:21 PM
why did you close the function block. before the if condition.
function checkRequired() {
var bunit = g_form.getValue('u_portfolio_bu');
var pqueue = g_form.getValue('u_primary_queue');
var vdriver = g_form.getValue('u_initiative');
var psuser = g_form.getValue('u_start_year');
if (bunit == '' && pqueue == '' && vdriver == '' && puser == '') {
g_form.setMandatory('u_portfolio_bu', true);
g_form.setMandatory('u_primary_queue', true);
g_form.setMandatory('u_initiative', true);
g_form.setMandatory('u_start_year', true);
g_form.showFieldMsg('u_portfolio_bu','u_primary_queue','u_initiative', 'u_start_year','is required to submit.', 'error');
}
gsftSubmit(null, g_form.getFormElement(), '<ui Action action name>'); //please mention your ui action "action name"
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 12:01 PM
Hello,
Please refer the below blog and adjust your code accordingly.
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
10-03-2017 12:21 PM
Please use the return false; to stop the form submission.
Also I think showFieldMsg() syntax is wrong, please refer: http://wiki.servicenow.com/index.php?title=GlideForm_(g_form)#showFieldMsg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 12:21 PM
why did you close the function block. before the if condition.
function checkRequired() {
var bunit = g_form.getValue('u_portfolio_bu');
var pqueue = g_form.getValue('u_primary_queue');
var vdriver = g_form.getValue('u_initiative');
var psuser = g_form.getValue('u_start_year');
if (bunit == '' && pqueue == '' && vdriver == '' && puser == '') {
g_form.setMandatory('u_portfolio_bu', true);
g_form.setMandatory('u_primary_queue', true);
g_form.setMandatory('u_initiative', true);
g_form.setMandatory('u_start_year', true);
g_form.showFieldMsg('u_portfolio_bu','u_primary_queue','u_initiative', 'u_start_year','is required to submit.', 'error');
}
gsftSubmit(null, g_form.getFormElement(), '<ui Action action name>'); //please mention your ui action "action name"
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2017 12:25 PM
Also, writing the Hello Love Me is quite fascinating