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.

By default check box field should be TRUE without depending on any other fields

Ksnow
Tera Contributor

Hi All, @shloke04 

There is a check box field called "Activate" under the section of "Times" in the form. I need "Activate" check box TRUE.

This section "Times" and fields under this section will be shown when the "Attach Time" check box is TRUE, so I tried to make "Activate" check box field true in the configure dictionary and it's not working.

So I decided to write UI policy script "when to apply" condition is "Attach Time is TRUE"

In script: Execute if true is " g_form.setValue('u_activate', true);" and Execute if false is " g_form.setValue('u_activate', false);" it's working fine.

Here my concern is under "Activate" check box there are a few duration fields like P1, P2 & P3. When user don't need these value they will uncheck "Activate" check box then P1, P2 & P3 fields will be hidden(using UI policy).

When user unchecked "Activate" check box and save the form, this field value is still TRUE because of the UI policy script.

How can I make "Activate" field TRUE  by default without based on "Attach Time" field?

Note; Tried default true in the config dictionary.

Please help!

Thanks,

Ksnow 

 

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Ksnow 

What you can do here is try to handle the logic in an On Change Client script including what is required on On Load as well in the same script:

1) Create a On Change Client script and use the sample script below:

First Scenario: When Attach checkbox is marked as True then display the field and Tabs you want in On Change Script and Also make Activate checkbox as True.

2) For the scenario where you are stuck, evaluate in the same On Change script that when Activate changes to false, hide the fields you want.

3) At the same time in the loading area of On Change client script, evaluate the oldValue of Activate checkbox and then control the visibility of fields P1, P2 etc.

Sample script shown below:

On Change script will be on Attach field, please make sure you select Attach field after selecting On Change Type in your client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        if (g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') == true) {
            g_form.setDisplay('Field Name', true);
			g_form.setDisplay('Field Name', true);
        }else if(g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') != true){
			g_form.setDisplay('Field Name', false);
			g_form.setDisplay('Field Name', false); // Field you want to hide
		}
        return;
    }
    if (newValue) {
        g_form.setDisplay('activate', true);
    }

    //Type appropriate comment here, and begin script below

}

 Along with this just have one UI Policy for showing or hiding Field P1, P2 on change of Activate checkbox.

This should work for your scenario.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

5 REPLIES 5

shloke04
Kilo Patron

Hi @Ksnow 

What you can do here is try to handle the logic in an On Change Client script including what is required on On Load as well in the same script:

1) Create a On Change Client script and use the sample script below:

First Scenario: When Attach checkbox is marked as True then display the field and Tabs you want in On Change Script and Also make Activate checkbox as True.

2) For the scenario where you are stuck, evaluate in the same On Change script that when Activate changes to false, hide the fields you want.

3) At the same time in the loading area of On Change client script, evaluate the oldValue of Activate checkbox and then control the visibility of fields P1, P2 etc.

Sample script shown below:

On Change script will be on Attach field, please make sure you select Attach field after selecting On Change Type in your client script

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        if (g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') == true) {
            g_form.setDisplay('Field Name', true);
			g_form.setDisplay('Field Name', true);
        }else if(g_form.getValue('Attach Field Name') == true && g_form.getValue('Activate Field Name') != true){
			g_form.setDisplay('Field Name', false);
			g_form.setDisplay('Field Name', false); // Field you want to hide
		}
        return;
    }
    if (newValue) {
        g_form.setDisplay('activate', true);
    }

    //Type appropriate comment here, and begin script below

}

 Along with this just have one UI Policy for showing or hiding Field P1, P2 on change of Activate checkbox.

This should work for your scenario.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke