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

Runjay Patel
Giga Sage

Hi @Saib1 ,

 

Checked the highlighted check box to apply you client script on item as well as sc task.

 

RunjayPatel_0-1729610852924.png

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.

Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

 

@Runjay Patel - Issue that it was showing all the variables . 

 

But my requirement it should show only the selected item in RITM and SCTASK

Hi @Saib1 ,

 

Change your client script to UI policy sometime client script wont work as expected. Try with one or 2 variable and see the impact. I am sure Ui Policy will help you here.

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.

Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

Josh Pirozzi
Kilo Sage

Hi @Saib1,

 

Why not use Catalog UI Policies where variable visibility is set based on the Type of Request (or other parameter), and you can configure one Catalog UI Policy for the Portal View and another for the RITM/SCTask view?

 

This may be a cleaner approach because you'll have the Policies to update when/if you update with new Variables.

 

Thanks,

 

Josh