Client script to make a field read only based on a condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2020 11:07 PM
Hi,
I have a field called as business service(reference field)on my incident form,Whenever business service is Unify(one of the values in the field) .I have to make the field read only after submission of the form.
ie.whenever the business service is Unify then when i save the form the field business service should be read only.
I wrote the onsubmit client script as below.
function onSubmit() {
//Type appropriate comment here, and begin script below
var bs = g_form.getValue('business_service');
if (bs == '4ba556dc1b04a4101f99db15ec4bcb0b') {
g_form.setReadonly('business_service', true);
}
}
but it isnt working.
when i click on save it becomes read only once the form is saved it is not shown as read only
Please can anyone help me
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 02:48 AM
Yes i have tried that as well,Still the same.
There is a ui policy also to make this field mandatory,but not read only.I am not supposed to change the mandatory in ui policy as there are other options also in this field where the business service should be mandatory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 03:02 AM
Hi,
then remove client script approach
1) use another UI policy with higher order than the current UI Policy
Condition: Created By [IS NOT EMPTY] -> so that it runs for existing record AND Business Service is Unify
UI Policy Actions:
Mandatory False
Readonly True
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 04:43 AM
It is showing the same on similar to onsubmit once the form is saved it again moves back to editable field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 05:06 AM
It is very difficult to say what's going wrong without checking or debugging
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 05:10 AM
Ok No Problem,Thanks for providing the solutions and suggestions