Some PDIs are currently unavailable, and PDI actions are paused. View the latest updates here. Read More

How to make variables mandatory or readonly if sc_task state will move cancell

Santosh Oraon
Tera Expert

Hi Everyone,

I need some guidance on a ServiceNow requirement.

When the SC Task (sc_task) state changes to Cancelled, I want to make certain catalog variables either mandatory or read-only.

What is the best way to achieve this? Should I use a Catalog Client Script, UI Policy, Business Rule, or another approach?

Any suggestions or examples would be appreciated. Thanks!

SantoshOraon_0-1785397805011.png

 

3 REPLIES 3

Chaitanya ILCR
Giga Patron

Hi @Santosh Oraon ,
you can create UI policy or onChange client script on the state filed on the catalog task table since catalog client script will not be having the state as variable go with UI policy or onChange client script on the table(catalog task)

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

Hi @Chaitanya ILCR , could you please tell how to get variables in ui policy?

Tanushree Maiti
Tera Patron

Hi @Santosh Oraon 

 

1) Try with this:

Create a new onChange Client Script with these configurations:

 

  • Type: onChange
  • UI Type: All
  • Field name: state

 

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

 var cat = g_form.getValue('request_item.cat_item');

   if (cat == '4a75538f0aaf39sdhjsdg9888e4fb76e') // your catalog item sys_id

   {

 

    // Replace '4' with your instance's exact 'Cancelled' state choice value if different

    if (newValue === '4') {

        // 1. Making certain variables Mandatory

       // Here instead of variables. your_variable_name_1 , if you use only your_variable_name_1 that will also work

 

        g_form.setMandatory('variables.your_variable_name_1', true);

        g_form.setMandatory('variables.your_variable_name_2', true);

 

        // 2. Making certain variables Read-Only

        g_form.setReadOnly('variables.your_variable_name_3', true);

        g_form.setReadOnly('variables.your_variable_name_4', true);

    } else {

        // Optional: Revert settings if the state is changed away from Cancelled

        g_form.setMandatory('variables.your_variable_name_1', false);

        g_form.setMandatory('variables.your_variable_name_2', false);

       

        g_form.setReadOnly('variables.your_variable_name_3', false);

        g_form.setReadOnly('variables.your_variable_name_4', false);

    }

}

}

 

 

2) check this as well :https://www.servicenow.com/community/developer-forum/how-to-make-a-field-mandatory-only-on-sc-task-f...

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti