- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 01:40 PM - edited 12-12-2023 01:43 PM
I am trying to set a variable field (variables.score_range) to mandatory if any of these three conditions are true. The script set the field to mandatory no matter the condition. Any help would be apricated. I don’t know what I am missing.
Conditions:
- If score.range is null
- If the is_the_enhancement_feasible = yes
- Or is_the_enhancement_feasible = null
function onSubmit() {
var task = g_form.getReference("request_item");
var cat_item = task.cat_item;
var state = g_form.getValue("state");
var actName = g_form.getActionName();
if(cat_item == 'SysID' && (state == '3' || actName == 'close_sc_task'))
{
//Set feasibility analysis fields to mandatory on close.
g_form.setMandatory('variables.score_range', true);
if(g_form.getValue('score_range') == '' &&
g_form.getValue('variables.is_the_enhancement_feasible') == 'Yes' ||
g_form.getValue('variables.is_the_enhancement_feasible') == ' ');{
alert('Please complete feasibility and fill request sizing before closing the task.');
return false;
}
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-13-2023 12:02 PM
I found the secret sauce. Now it is working
function onSubmit() {
var task = g_form.getReference("request_item");
var cat_item = task.cat_item;
var state = g_form.getValue("state");
var actName = g_form.getActionName();
if(cat_item == 'SysID' && (state == '3' || actName == 'close_sc_task'))
{
var feasibility = g_form.getValue('variables.is_the_enhancement_feasible');
var project_checkbox = g_form.getBooleanValue("variables.project_checkbox");
//Set feasibility analysis fields to mandatory on close.
if(feasibility != 2 && project_checkbox == false)
{
g_form.setMandatory('variables.score_range', true);
alert('Please complete feasibility and fill request sizing before closing the task.');
return false;
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 01:48 PM
You need to nest the g_form.setMandatory() call inside your if statement. Currently it is outside of it so it will always be mandatory no matter if your conditions are true/false.
function onSubmit() {
var task = g_form.getReference("request_item");
var cat_item = task.cat_item;
var state = g_form.getValue("state");
var actName = g_form.getActionName();
if (cat_item == 'SysID' && (state == '3' || actName == 'close_sc_task')) {
//Set feasibility analysis fields to mandatory on close.
if (g_form.getValue('score_range') == '' &&
g_form.getValue('is_the_enhancement_feasible') == 'Yes' ||
g_form.getValue('is_the_enhancement_feasible') == ' '); {
g_form.setMandatory('score_range', true);
alert('Please complete feasibility and fill request sizing before closing the task.');
return false;
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 03:38 PM
Than you for the responce!
This still sets the field to mandatory if I select no for is_the_enhancement_feasible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 04:33 PM
I have made few correction to you script. For ex g_form.getValue('score_range') should be g_form.getValue('variables.score_range'). Can you try below script? If variables.score_range doesnt work, another option is using Display Business Rule to get values of this variables in scratchpad and then use in the onSubmit script.
function onSubmit() {
var task = g_form.getReference("request_item");
var cat_item = task.cat_item;
var state = g_form.getValue("state");
var actName = g_form.getActionName();
if(cat_item == 'SysID' && (state == '3' || actName == 'close_sc_task'))
{
//Set feasibility analysis fields to mandatory on close.
if(g_form.getValue('variables.score_range') == '' &&
g_form.getValue('variables.is_the_enhancement_feasible') != 'No');{
g_form.setMandatory('variables.score_range', true);
alert('Please complete feasibility and fill request sizing before closing the task.');
return false;
}
}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:09 PM
Thank you.
I made the changes, but still when I select no for the is_the_enhancement_feasible, the field scope.range is still made mandatory.