client script if I select the state as In progress means I want to make field 1 visible in incident form

Dhivya10
Tera Contributor

I created 4 fields as field1,field2,field3,field4 in incident form. If I select the In progress state means I want field1 should be visible and mandatory rest of field2,field3,field4 should not visible in incident form..

1 ACCEPTED SOLUTION

Voona Rohila
Kilo Patron
Kilo Patron

Hi Dhivya

Did you try anything so far and got stuck? it's easy and doesnt require any script to do with UI Policies.

try this

if(newValue=="in progress state backend value") // please replace work in progress choice backend value
{
g_form.setDisplay('field1',true);
g_form.setMandatory('field1',true)
g_form.setDisplay('field2',false);
g_form.setDisplay('field3',false);
g_form.setDisplay('field4',false);
}
else
{
//modify below statements accordingly if you want to show the fieldss if state is not inprogress.
g_form.setMandatory('field1',false); 
g_form.setDisplay('field2',false);
g_form.setDisplay('field2',true);
g_form.setDisplay('field3',true);
g_form.setDisplay('field4',true);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

5 REPLIES 5

Voona Rohila
Kilo Patron
Kilo Patron

Hi Dhivya

Did you try anything so far and got stuck? it's easy and doesnt require any script to do with UI Policies.

try this

if(newValue=="in progress state backend value") // please replace work in progress choice backend value
{
g_form.setDisplay('field1',true);
g_form.setMandatory('field1',true)
g_form.setDisplay('field2',false);
g_form.setDisplay('field3',false);
g_form.setDisplay('field4',false);
}
else
{
//modify below statements accordingly if you want to show the fieldss if state is not inprogress.
g_form.setMandatory('field1',false); 
g_form.setDisplay('field2',false);
g_form.setDisplay('field2',true);
g_form.setDisplay('field3',true);
g_form.setDisplay('field4',true);
}

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP