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.

Need to restrict the variables in Request Item and SCTASK

Saib1
Tera Guru

HI All 

 

We have the Service Catalog and contains Group Type - Create/Update/Delete

 

1. When i select the Create it shows only the Create related variables

 

Saib1_0-1729610259800.png

2. Filled all the values clicked Order Now and RITM got created

 

Saib1_1-1729610374711.png

 

I am seeing that Request Item contain all the variables . How to restrict? It should show only for the Create related variables  not others variables

 

===================================================================================

I have done few client script below on the catalog items

 

function onLoad() {
g_form.setVisible('number_of_group_creation',false);
    g_form.setMandatory('number_of_group_creation',false);
        g_form.setDisplay('number_of_group_creation',false);

        g_form.setVisible('number_of_group_updation',false);
    g_form.setMandatory('number_of_group_updation',false);
        g_form.setDisplay('number_of_group_updation',false);

        g_form.setVisible('number_of_group_deletion',false);
    g_form.setMandatory('number_of_group_deletion',false);
        g_form.setDisplay('number_of_group_deletion',false);


            g_form.setVisible('new_group_creation_details',false);
    g_form.setMandatory('new_group_creation_details',false);
        g_form.setDisplay('new_group_creation_details',false);

            g_form.setVisible('group_updation_details',false);
    g_form.setMandatory('group_updation_details',false);
        g_form.setDisplay('group_updation_details',false);

            g_form.setVisible('delete_group_details',false);
    g_form.setMandatory('delete_group_details',false);
        g_form.setDisplay('delete_group_details',false);

                g_form.setVisible('Notes',false);
    g_form.setMandatory('Notes',false);
        g_form.setDisplay('Notes',false);
   
}
 
 ==================================================================================
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    g_form.clearValue("number_of_group_creation");
    g_form.clearValue("number_of_group_updation");
    g_form.clearValue("number_of_group_deletion");

    g_form.clearValue("delete_group_details");
    g_form.clearValue("group_updation_details");
    g_form.clearValue("new_group_creation_details");

    if (g_form.getValue('group_type1') == "create") {

        g_form.setVisible('number_of_group_creation', true);
        g_form.setMandatory('number_of_group_creation', true);
        g_form.setDisplay('number_of_group_creation', true);

        g_form.setVisible('number_of_group_updation', false);
        g_form.setMandatory('number_of_group_updation', false);
        g_form.setDisplay('number_of_group_updation', false);

        g_form.setVisible('number_of_group_deletion', false);
        g_form.setMandatory('number_of_group_deletion', false);
        g_form.setDisplay('number_of_group_deletion', false);


        g_form.setVisible('new_group_creation_details', true);
        g_form.setMandatory('new_group_creation_details', true);
        g_form.setDisplay('new_group_creation_details', true);

        g_form.setVisible('group_updation_details', false);
        g_form.setMandatory('group_updation_details', false);
        g_form.setDisplay('group_updation_details', false);

        g_form.setVisible('delete_group_details', false);
        g_form.setMandatory('delete_group_details', false);
        g_form.setDisplay('delete_group_details', false);

        g_form.setVisible('Notes', false);
        g_form.setMandatory('Notes', false);
        g_form.setDisplay('Notes', false);


    } else if (g_form.getValue('group_type1') == "update") {

        g_form.setVisible('number_of_group_creation', false);
        g_form.setMandatory('number_of_group_creation', false);
        g_form.setDisplay('number_of_group_creation', false);

        g_form.setVisible('number_of_group_updation', true);
        g_form.setMandatory('number_of_group_updation', true);
        g_form.setDisplay('number_of_group_updation', true);

        g_form.setVisible('number_of_group_deletion', false);
        g_form.setMandatory('number_of_group_deletion', false);
        g_form.setDisplay('number_of_group_deletion', false);


        g_form.setVisible('new_group_creation_details', false);
        g_form.setMandatory('new_group_creation_details', false);
        g_form.setDisplay('new_group_creation_details', false);

        g_form.setVisible('group_updation_details', true);
        g_form.setMandatory('group_updation_details', true);
        g_form.setDisplay('group_updation_details', true);

        g_form.setVisible('delete_group_details', false);
        g_form.setMandatory('delete_group_details', false);
        g_form.setDisplay('delete_group_details', false);

        g_form.setVisible('Notes', false);
        g_form.setMandatory('Notes', false);
        g_form.setDisplay('Notes', false);

    } else if (g_form.getValue('group_type1') == "delete") {

        g_form.setVisible('number_of_group_creation', false);
        g_form.setMandatory('number_of_group_creation', false);
        g_form.setDisplay('number_of_group_creation', false);

        g_form.setVisible('number_of_group_updation', false);
        g_form.setMandatory('number_of_group_updation', false);
        g_form.setDisplay('number_of_group_updation', false);

        g_form.setVisible('number_of_group_deletion', true);
        g_form.setMandatory('number_of_group_deletion', true);
        g_form.setDisplay('number_of_group_deletion', true);


        g_form.setVisible('new_group_creation_details', false);
        g_form.setMandatory('new_group_creation_details', false);
        g_form.setDisplay('new_group_creation_details', false);

        g_form.setVisible('group_updation_details', false);
        g_form.setMandatory('group_updation_details', false);
        g_form.setDisplay('group_updation_details', false);

        g_form.setVisible('delete_group_details', true);
        g_form.setMandatory('delete_group_details', true);
        g_form.setDisplay('delete_group_details', true);

        g_form.setVisible('Notes', true);
        g_form.setMandatory('Notes', false);
        g_form.setDisplay('Notes', true);
    }

}
 
 
 
6 REPLIES 6

@Josh Pirozzi 

 

for the --NONE-- the ui policy is not working . CAn you correct if anything wrong here

 

Saib1_0-1729618571644.pngSaib1_1-1729618593678.png

 

@Saib1,

You may need to adjust the conditions to 'group_type1' IS NOT ONE OF and select all of the Select Box options to hide the other Variables. 

 

A couple of other things I've found recently are:

  1. Using different UI Policy Order numbers is necessary.
  2. Review/verify if there is another UI Policy trying to do the same thing that is conflicting with this UI Policy.