Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Removing Request Status choices for Mandatory tasks

aguanci
Tera Expert

Hi All,

 

Struggling with what should be a straightforward Client Script for HR Task. Our goal is listed below:

  • Remove Cancelled/Closed Incomplete for Mandatory Tasks within Activity Set
  • Remove Cancelled for Manadatory Ad-hoc Tasks
  • Keep both for any Optional Task

With the script below I am able to remove both choices but it only fits one of the scenarios above. I have researched this and have a feeling I am supposed to call an if else statement but do not know what to call for the else. 

Table: HR Task

Type: onChange

Script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   
var opt = g_form.getValue('optional');

    if (opt != 'true') {
        g_form.removeOption('state', '7');
        g_form.removeOption('state', '4');
    }
}

 

Any help would be appreciated! 

 

1 REPLY 1

The Machine
Mega Sage

Yeah, you might need an else statement and then g_form.addOption functions to add them back.

If the onChange is on the variable ('optional').  You could also use "newValue".  

if(newValue != true)