- 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 07:43 PM - edited ‎12-12-2023 07:45 PM
Hi @ronyates
There's a semicolon (;) at the line If Statement in your script. Let's use SanjivMeher script and remove it out, it should do the trick.
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') { //remove semicolon at this line
g_form.setMandatory('variables.score_range', true);
alert('Please complete feasibility and fill request sizing before closing the task.');
return false;
}
}
}
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-13-2023 10:22 AM
This is still not working. When I select No for is_the_enhancement_feasible, the field should not be made mandatory but it still is.
I have tried several different varaitions of the if condition and still get the same results.
I added this:
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')) {
- 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;
}
}
}