Not able to make hide fields, readonly & mandatory in PDI
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2023 08:56 PM
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 :-
On Load Script :-
On Change Script :-
Thanks,
Krishnakant Yadav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 08:43 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2023 09:42 PM
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