How to make same varaible manadatory in 1st task and Read only in 2nd task

Gopal14
Tera Contributor

Hi Team,

 

How to make same variable mandatory in 1st task and Read only in 2nd task.

 

Variable is only available on the catalog task form, not on the RITM.

 

I have written a UI Policy to make variable visible on task. On same UI Policy I am making mandatory. After closing 1st task, 2nd task will be open.

 

Now I have written a client script to make 2nd task variable read only, But It is not working. 

 

Gopal14_0-1731067070526.png

 

 

I know client script is having highest preference, than UI Policy.

 

How Can I achieve this?

3 REPLIES 3

Najmuddin Mohd
Mega Sage

Hi @Gopal14 ,

You can follow the below process.

1. Select the Hidden Check box for the variable.
2. Now, Create the a UI Policy, 

Conditions,
variable_name isEmpty

UI Policy Actions,
variable_name : Visible - True, Mandatory - True


3. Now, Create another UI Policy,
Conditions,
Variable is Not Empty
UI Policy Actions

variable_name: Visible - True, Read only - True

First task

NajmuddinMohd_1-1731069520417.png


Second task.

NajmuddinMohd_2-1731069526356.png



When you add the details, it becomes mandatory.

One thing, even in first catalog task when you fill and did not save the form, you may see that the field is Read 0nly.

But, Once you reload, the value is empty and it becomes mandatory.


If the above information Helps you, Kindly mark it as Helpful and Accept the solution.
Regards,
Najmuddin.

 


               

Ashish Parab
Mega Sage

Hi @Gopal14 

 

Instead of creating a UI policy for the first task and a client script for the second task, you can try creating a single onLoad client script for both tasks, as shown below,

 

function onLoad() {
   //Type appropriate comment here, and begin script below
   var shortDescription = g_form.getValue('short_description');
   if(shortDescription == 'your_first_task_short_description'){
	g_form.setVisible('your_variable_name',true);
	g_form.setMandatory('your_variable_name',true);
   }else if(shortDescription == 'your_second_task_short_description'){
	g_form.setMandatory('your_variable_name',false);
	g_form.setReadOnly('your_variable_name',true);
   }
   
}

 

 

Please mark this as "correct" and "helpful" if you feel this answer helped you in anyway.

 

Thanks and Regards,

Ashish

Runjay Patel
Giga Sage

Hi @Gopal14 ,

 

You can use below script in onload client script.

function onLoad() {
   
   var shortDescription = g_form.getValue('short_description');

   if(shortDescription == 'your_first_task_short_description')
	g_form.setMandatory('your_variable_name',true);
   else if(shortDescription == 'your_second_task_short_description')
	g_form.setReadOnly('your_variable_name',true);
   
   
}

 

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

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
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

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