How to Enable All Fields on a Table for Editing But Lock Specific Columns in Dynamics 365

By Ron Ellison | November 7, 2024

If you want to make all views editable for a specific table but lock certain columns so they cannot be changed from view in Dynamics 365, you can follow a series of steps.

  1. In Dynamics 365, enter Advanced Settings
  2. Click Settings > Customizations
  3. Click Customize the System
  4. Under Entities select the table you want to make views editable
  5. Click the Controls tab
  6. Click Add Control..
  7. Scroll down and select “Power Apps grid control”
  8. Click Add
  9. Click the Web radio button
  10. Select the Power Apps grid control and scroll down the list of property items to Enable editing
  11. Click the edit button and change to Yes
    Lock Specific Columns Click edit button
  12. Close Entities
  13. Create a new Javascript file (*.js) (Visual Studio, Notepad++, etc)
  14. Create the javascript code using the following:
    function onRecordSelect(exeContext) {
    //debugger;
    var _formContext = exeContext.getFormContext();
    var disableFields = ["name","msdyn_company"];
    lockFields(exeContext, disableFields);
    }
    
    function lockFields(exeContext, disableFields) {
    var _formContext = exeContext.getFormContext();
    var currentEntity = _formContext.data.entity;
    currentEntity.attributes.forEach(function (attribute, i) {
    if (disableFields.indexOf(attribute.getName()) > -1) {
    var attributeToDisable = attribute.controls.get(0);
    attributeToDisable.setDisabled(true);
    }
    });
    } 
    
  15. Replace the green highlighted text with the field schema names you want to lock on all views
    1. Each name is in quotes and separated by a comma ["name","msdyn_company"]
  16. Save the file as a .JS file
  17. In a solution, Create a new web resource
  18. Enter a Name and Display Name
  19. Choose Script (Jscript) as the Type
  20. Click Choose File and select the JS file created earlier.
    Lock Specific Columns Choose file
  21. Click Save
  22. Click Publish
  23. In your solution, open Entities and click the entity again (I am using the Account entity as an example)
  24. Click Events
  25. Under Form Libraries, click add
  26. Add the new web resource created earlier
    Lock Specific Columns new web resources
  27. Under Event Handler, change the Event to OnRecordSelect
  28. Click + Add
  29. Choose the new library from the list
  30. Enter the Function name as show in the image below
  31. Click the Pass execution context as first parameter
    Handler Properties
  32. Click OK

Reach out to Stoneridge Software to Learn More About Optimizing Dynamics 365

No matter which Dynamics 365 solutions you are running, Stoneridge experts can help you customize and optimize it so it works for your business' specific needs.

Contact us to learn more.

Related Posts


Under the terms of this license, you are authorized to share and redistribute the content across various mediums, subject to adherence to the specified conditions: you must provide proper attribution to Stoneridge as the original creator in a manner that does not imply their endorsement of your use, the material is to be utilized solely for non-commercial purposes, and alterations, modifications, or derivative works based on the original material are strictly prohibited.

Responsibility rests with the licensee to ensure that their use of the material does not violate any other rights.

Start the Conversation

It’s our mission to help clients win. We’d love to talk to you about the right business solutions to help you achieve your goals.

Subscribe To Our Blog

Sign up to get periodic updates on the latest posts.

Thank you for subscribing!