Hi,
I want to lock all the fields in the form based on the value user selects in an option type field.
Eg:
If the user selects Contact type = A, the user should be able to edit the fields but of Contact type = B, the form should lock all the fields and make it read only.
I could have done it using business rules but there are more than 100 fields so it will take time. IS there a way to do with JS ? If anyone could help ?
The main issue was the function name. I changed that and it is working now. Thank you.
Hi Prajwal Bhetwal,
According to the error message, the result of formContext.getAttribute("boq_contacttype") is null.
And as Bipin Kumar says, you need check the field's logical name and if this field on your form.
1.Check the field's logical name:
2. Check the field is on your form or not:
If the issue persists, please clear the cache of browser.
BTW, the function name should be onload.
And if you change the in your web resource, please remember to reupload your code and publish again.
Hi,
I would recommend you to debug your code
Please recheck if contact type field is added on the form.
Yes, the schema name is boq_contacttype and the field is present in the form as well.
I've changed the attribute name in the code to match the schema name. But still, I'm getting errors.
Hi,
Please make sure that contact type field schema name is correct and field is present on the form.
Hi
I've made this little change in the code so that for all other option type read-only is disabled except one contact type.
I've added the form on load as well.
When the form loads I'm getting this error "One of the scripts for this record has caused an error. For more details, download the log file."
Cannot read properties of null (reading 'getValue')
How can I fix this error?
Hi
I've made this little change in the code so that for all other option type read-only is disabled except one contact type.
I've added the form on load as well.
When the form loads I'm getting this error "One of the scripts for this record has caused an error. For more details, download the log file."
Cannot read properties of null (reading 'getValue')
How can I fix this error?
Hi Steve, this is exactly what I want.
But I am very new to d365 CRM so I don't know who I can create an onLoad event in CRM. If there is any document around it that you could pass it would be great.
Hi
Please create an onload event with the following code(Change the logical name of field and field value to yours):
function onload(executionContext){ var formContext = executionContext.getFormContext(); var contactType = formContext.getAttribute("cr1bc_contacttype"); lockAllFields(executionContext); contactType.addOnChange(lockAllFields); } function lockAllFields(executionContext){ var formContext = executionContext.getFormContext(); var contactType = formContext.getAttribute("cr1bc_contacttype").getValue(); var allControls = formContext.ui.controls; //contactType == "A" if(contactType == 516560000){ allControls.forEach((ctrl,index)=>{ctrl.setDisabled(false)}) }else if(contactType == 516560001){ allControls.forEach((ctrl,index)=>{ctrl.setDisabled(true)}) } //if you need contactType still editable //formContext.getControl("cr1bc_contacttype").setDisabled(false); }
Result:
Type B
Type A
I want to make the form read-only when the user selects a certain option set value. I don't want it to be read-only all the time.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156