Not able to make hide fields, readonly & mandatory in PDI

krishnakant
Tera Contributor

Hi Developers,

 

Greetings to all!!

 

I am a not able to make fields readOnly, Mandatory and also not able to hide fields on Incident form in My PDI. I am also not sure why this is happening. I have checked another scripts as well but but didn't find any script that is conflicting.

 

If anyone faced similar issue or having any ideas why this is happening please let me know.

 

Adding SS for reference :-

krishnakant_0-1691898669451.pngkrishnakant_1-1691898716776.png

On Load Script :- 

krishnakant_2-1691898860469.png

On Change Script :- 

krishnakant_3-1691898950372.png

 

Thanks,

Krishnakant Yadav

 

2 REPLIES 2

tharun_kumar_m
Mega Guru

Hi Krishnakant,

 

To set fields read only, please try this statement g_form.setReadOnly("field_name",true); 

To make a field mandatory, follow this https://docs.servicenow.com/en-US/bundle/vancouver-platform-administration/page/administer/field-adm...

 

And use a conditional statement in your scripts to apply your conditions to only the roles you want to apply.

 

As an admin you automatically assume all roles.  Try the following condition:

 

if (!g_user.hasRole('admin')) {}

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumbs up.

 

Best regards,

Tharun Kumar

Sagar Pagar
Tera Patron

Hi @krishnakant,

 

I would suggest to use the UI policies instead of Client scripts to make fields read-only, mandatory and show/hide based on conditions.


If my response helps to solve your issue. Kindly mark it as helpful & correct. It will be helpful for future readers.
Thanks,
Sagar Pagar

The world works with ServiceNow