At times, you use Editable Grid and by default – all the fields which are editable by the system are exposed and can be edited if they are present on the Editable Sub-grid. You might not want to allow all fields to be editable on the Editable Grid – so here’s how you can lock selected fields on the Editable Grid using JavaScript.
Use Case
Let’s look at the below example where by default, the fields are Editable because you are using an Editable Grid –
- You might want to lock the Status field since it shouldn’t be something end user should be able to change by themselves.
- So in such scenarios, you might want to keep most fields open but lock some of them on the Editable Grid itself. Let’s see how we can do it using JavaScript
JavaScript Code
Here’s a sample code which you can use to loop through all the fields you want to lock on the Editable Grid –
- Code within a class – [You can just use the lockFields function separately too.]
oSubscriptionCustomization = {
lockFields: function (executionContext) {
var oFormContext = executionContext.getFormContext();
if (oFormContext) {
var arrFields = ["cft301_status"];
var objEntity = oFormContext.data.entity;
objEntity.attributes.forEach(function (attribute, i) {
if (arrFields.indexOf(attribute.getName()) > -1) {
let attributeToDisable = attribute.controls.get(0);
attributeToDisable.setDisabled(true);
}
})
}
}
}; - In the above code, I’m reading from an array called arrFields and all the fields listed in the array will be looped through and locked.
- Once my JS file is ready, I can open the Editable Grid control itself on the parent form and then loop for Events tab to register my function on the grid.
- In the Event tab, look for the UI Event called as OnRecordSelect
- Here, you can register your function. Since, I’m using class too – I’ll use classname.functionName
- Once done, save and publish your changes. Now, you’ll see that the field is locked when you select the record on the Editable Grid.
Hope this was useful!
Here are some Power Automate posts you want to check out –
- Select the item based on a key value using Filter Array in Power Automate
- Select values from an array using Select action in a Power Automate Flow
- Blocking Attachment Extensions in Dynamics 365 CRM
- Upgrade Dataverse for Teams Environment to Dataverse Environment
- Showing Sandbox or Non Production Apps in Power App mobile app
- Create a Power Apps Per User Plan Trial | Dataverse environment
- Install On-Premise Gateway from Power Automate or Power Apps | Power Platform
- Co-presence in Power Automate | Multiple users working on a Flow
- Search Rows (preview) Action in Dataverse connector in a Flow | Power Automate
- Suppress Workflow Header Information while sending back HTTP Response in a Flow | Power Automate
- Call a Flow from Canvas Power App and get back response | Power Platform
- FetchXML Aggregation in a Flow using CDS (Current Environment) connector | Power Automate
- Parsing Outputs of a List Rows action using Parse JSON in a Flow | Common Data Service (CE) connector
- Asynchronous HTTP Response from a Flow | Power Automate
- Validate JSON Schema for HTTP Request trigger in a Flow and send Response | Power Automate
- Converting JSON to XML and XML to JSON in a Flow | Power Automate
Thank you!