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

Harish KM
Kilo Patron
Kilo Patron

Hi you can use UI Policy

Condition: state is In progress

Field 1 : visible true , Mandatory: true

field 2,3,4: visible false

Regards
Harish

how to make it in client scripts..

Hi Avoid Client scripts if you can achieve it through UI Policy. Always follow best practices .

Regards
Harish

Mohith Devatte
Tera Sage
Tera Sage

Hello ,

You can write a on change client script for this on state field 

script:

if(newValue=="in progress state backend value") // please replace work in progress choice backend value

{

g_form.setMandatory('field1',true)

g_form.setVisible('field2',false);

g_form.setVisible('field3',false);

g_form.setVisible('field4',false);

}

else

{

g_form.setMandatory('field1',false)

g_form.setVisible('field2',true);

g_form.setVisible('field3',true);

g_form.setVisible('field4',true);

}

OR you can congigure a Ui ploicy to do the same.To know how to create Ui policy follow below link

https://developer.servicenow.com/dev.do#!/learn/learning-plans/sandiego/new_to_servicenow/app_store_...

Please accept the solution and close the thread if this helps you 

thanks