How to make field readonly using client script(scoped application)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 02:46 AM
Hi Experts,
We have a requirement to make reference field (bo_reference) readonly when check box (is bo inherited) is made false and form view should be module_data.
Have tried below onload and onchange scripts.
Onchange:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
var view = getView();
//alert(view);
var isBOInherited = g_form.getValue('is_bo_inherited');
//alert(isBOInherited);
if (view == 'module_data') {
//if (isBOInherited == 'true') {
if (newValue == 'true') {
g_form.setReadOnly('bo_reference', true);
//g_form.setValue('bo_reference', '');
alert(bo_reference +'bo_reference');
// g_form.setMandatory('bo_reference', 'true');
}
else if (isBOInherited == 'false') {
g_form.setMandatory('bo_reference', 'false');
g_form.setReadOnly('bo_reference', 'true');
}
}
}
OnLoad:
function onLoad() {
var view = getView();
//alert('view is = ' + view);
var isBOInherited = g_form.getValue('is_bo_inherited');
// alert(isBOInherited);
//bo_referenceISEMPTY
if (view == 'module_data') {
if (isBOInherited == false) {
g_form.setMandatory('bo_reference', false);
g_form.setReadOnly('bo_reference', true);
} else {
g_form.setReadOnly('bo_reference', false);
g_form.setMandatory('bo_reference', true);
}
}
//Type appropriate comment here, and begin script below
}
.
Thanks Jay.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-23-2022 09:19 PM
In your onchange client script, make the below change:
In else if block, try g_form.setReadOnly('bo_reference', false); instead of making it true.
Please mark my response as helpful/correct if this helps