Skip to main content

Notifications

Dynamics 365 general forum
Suggested answer

Read Only Form Once Approved

Posted on by 50

Hello All, 

How can I lock the entire form  "read only" when the approval box is checked off. I tried using business rules but I have to do one field at a time. I have over 30 fields on this form. 

  • Manny Floyd Profile Picture
    Manny Floyd 50 on at
    RE: Read Only Form Once Approved

    Hi Ricardo, thanks. Will try to modify this code and make it work.

  • Manny Floyd Profile Picture
    Manny Floyd 50 on at
    RE: Read Only Form Once Approved

    Hi Tyler,

    I am actually using Inactive and Active feature. So to answer your question, yes, the record can be approved and inactive. If the record is approved, all fields needs to be locked.

    I will truly appreciate your help. Dead line is approaching soon.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Read Only Form Once Approved

    Hi Emanual

    I had a similar requirement for a customer and this can be done via a simple JavaScript function which I am willing to share with you or you can use a simple workflow to make the record inactive which in turn will make the record read-only. My question here is, does the record have to be active and fields read-only, or can the entire record be deactivated?

  • RE: Read Only Form Once Approved

    Well observed. Thanks for that!

  • Henry J. Profile Picture
    Henry J. 5,235 on at
    RE: Read Only Form Once Approved

    One small comment: Xrm.Page still works but is deprecated, so I would advise to use ExecutionContext.getFormContext instead.
    You can find guidance on this here:
    https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated 

  • Suggested answer
    RE: Read Only Form Once Approved

    Hi Emanuel,

    Here is a good sample to inspire you build your solution:

    ==============================================================

    function MakeAttributesReadOnlyExceptOne(){

    Xrm.Page.data.entity.attributes.forEach(

    function (attribute, index) {

    var attributeName = attribute.getName();

    if (attributeName == "FieldLogicalName"){ //The field which you do not need to make read only

    Xrm.Page.getControl(attributeName).setDisabled(false);

    }

    else{

    Xrm.Page.getControl(attributeName).setDisabled(true);

    }

    });

    }

    ==============================================================

    Thanks,

  • Manny Floyd Profile Picture
    Manny Floyd 50 on at
    RE: Read Only Form Once Approved

    Thank you both. I am not great in JS - can you provide me a reference site. I'm in a middle of learning JS.

  • RE: Read Only Form Once Approved

    Hi Emanuel,

    As quoted by Henry, a JavaScript custom code would be the best approach here. As you said, Business Rule only allowed this action configuring one attribute at the time.

    Thanks,

  • Suggested answer
    Henry J. Profile Picture
    Henry J. 5,235 on at
    RE: Read Only Form Once Approved

    Hello Emanuel,

    This could be done in JavaScript with formContext.data.entity to retrieve the list of attributes and setDisabled.

    Another way to approach this to set the record status as inactive once your process is done.
    That way, the record becomes read-only in the user interface.

    Henry

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

News and Announcements

Give Back to the Community this Month

Quick Links

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,807 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,135 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans