How to make same varaible manadatory in 1st task and Read only in 2nd task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 03:59 AM
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.
I know client script is having highest preference, than UI Policy.
How Can I achieve this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 04:43 AM
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
Second task.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 05:01 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-08-2024 05:08 AM
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
-------------------------------------------------------------------------