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
‎11-30-2020 11:49 PM
Hi Ankur,
My requirement is when i create a new incident and if business Service is Unify,and once the form is submitted it should show the field business service as read only.
I checked for ui policies also,there isnt any ui policy on the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-30-2020 11:56 PM
Hi,
try adding alerts in that onLoad client script
function onLoad() {
//Type appropriate comment here, and begin script below
var bs = g_form.getValue('business_service');
if (bs == '4ba556dc1b04a4101f99db15ec4bcb0b' && !g_form.isNewRecord()) {
alert('inside');
g_form.setReadonly('business_service', true);
}
}
If this setup is in your personal instance and you are ok to share details url and some admin credentials then share here -> ankurb.snow@gmail.com
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 12:12 AM
Hi Ankur,
Thanks for the consideration,but this is not my personal instance.
I tried adding the alert.it isnt taking that as well.
if possible Could you please tell me if there is any other way I can achieve this requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 01:08 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-01-2020 02:21 AM
Hi Ankur,
I tried the alert again
Its taking the alert inside the loop but the field not becoming mandatory.