Skip to main content

Notifications

Power Pages - Power Apps Portals
Answered

How to Control Editable Fields in Power Pages Based on Dataverse Data?

Like (0) ShareShare
ReportReport
Posted on 28 Jan 2025 14:42:43 by 2
Hi everyone,
I’m working on a Power Apps Portal and Model-Driven App in a test environment. Currently, I have a setup where an applicant submits an application form through a Power Pages Portal, and this creates a case in Dataverse. Caseworkers manage these cases in a Model-Driven App using a Business Process Flow. If additional information is required, the caseworker can specify which fields in the application need to be updated using an embedded Canvas App. This information is then saved in a column in Dataverse, where the editable fields are stored as an array of field names.
When the applicant returns to the portal to edit their application, only the fields marked by the caseworker as requiring updates should be editable, while all other fields should remain read-only. Currently, this behaviour is achieved by hardcoding the editable fields into the JavaScript running on the portal page.
I would like to replace this with a dynamic approach that fetches the editable fields directly from Dataverse and adjusts the form behaviour accordingly. Specifically, how can I use the JSON data saved in Dataverse to control field editability in the portal? I have some ideas but just not sure if I’m approaching it correctly so any advice or best practices would be greatly appreciated.
Thank you!
Categories:
  • Inogic Profile Picture
    Inogic 901 on 30 Jan 2025 at 05:57:39
    How to Control Editable Fields in Power Pages Based on Dataverse Data?
    Hi,

    To achieve this dynamically, Liquid is used to fetch the editable fields stored in Dataverse, and JavaScript is used to adjust the form behavior accordingly.

    1. Use Liquid to retrieve the editable_fields column (which contains the array of field names) from Dataverse:
                      Liquid

                      {% assign caseId = request.params['caseId'] %}
                      {% assign case = entities.cases[caseId] %}
                      {% assign editableFields = case.editable_fields %}

    ​​​​​​​2. ​​​​​​​Once the editable fields are retrieved, inject them into JavaScript and apply the necessary logic. put the below code in script tag
      
        const editableFields = {{ editableFields | json }};
       
        document.addEventListener("DOMContentLoaded", function() {
            document.querySelectorAll("input, select, textarea").forEach(field => {
                if (editableFields.includes(field.name)) {
                    field.removeAttribute("readonly");
                    field.removeAttribute("disabled");
                } else {
                    field.setAttribute("readonly", "true");
                    field.setAttribute("disabled", "true");
                }
            });
        });



    Hope this helps.
     

    Thanks!

    Inogic Professional Services: Power Platform/Dynamics 365 CRM
    An expert technical extension for your techno-functional business needs
    Drop an email at crm@inogic.com 
    Service: https://www.inogic.com/services/ 
    Tips and Tricks: https://www.inogic.com/blog/ 
  • Verified answer
    Fubar Profile Picture
    Fubar 7,690 on 28 Jan 2025 at 23:42:26
    How to Control Editable Fields in Power Pages Based on Dataverse Data?
    If you are saving the list of fields to the same record, then
    • add the field that holds them to the Form and set it read only and to not show its label.
    • Then in the Power Pages Management App add a Metadata record to the form for the field that is holding the list and specify a CSS class to hide that field.
    • Then use JS to read from the fields from the list
    You say you already hard coded it, so the above should be enough to move you forward.
    You could also use the Web API (but this will be slower as your page needs to load before the call to the API can be made), or retrieve the list by using Liquid on the Web Page in question (bit more tricky if using the modal popups an not the form in a Web Page) and from the LIquid set a Javascript variable.

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

Quick Links

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,666

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,996

Leaderboard
Loading started