web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

File input on form - how to lock? (PowerApps, model driven)

(0) ShareShare
ReportReport
Posted on by 25

Hi everyone,

We're using PowerApps to build a model driven app that uses the "file" type column in a table. As I understand it, this option hasn't been available for model driven apps for very long. The file upload control on a form works fairly well. It takes the selected file and stores this directly in the appropriate Dataverse table column. However, we cannot disable this file input with a business rule somehow. Business Rule editor simply doesn't give the option.

lock

The plan is to use JavaScript to disable the input when it needs to be disabled. The JavaScript however does not get access to the targeted section (containing the button input we need to grab) using id (getElementById). The section ID can be controlled from the classic form edit view. So, if the section is grabbed, we can then search for the button and disable it. But the section appears to be generated after the onLoad event finishes. The result is, that I can grab the section when I run "document.getElementById('my_specific_section_id')" from the browser console, but when the application executes the script, it always results in null.

The section can't be found. This is only the case when using the file input form field. Other elements can be found as expected. In Dynamics365 user groups I was reading about how getlementById is not supported there. But given the fact that I can use this to grab other elements, I think it is not the case here.

What can I do to get the file input field disabled (as in "locked", unable to select a file, or delete one if one is already there)?

Best regards,
- Alex

I have the same question (0)
  • Verified answer
    Pradeep Rai Profile Picture
    5,489 Moderator on at
    RE: File input on form - how to lock? (PowerApps, model driven)

    Hi Alex,

    In order to access the CRM fields/Controls, we need to write CRM based script as described below:

    For this, i have one custom entity named as "Employee" and created one File Type Field as "File Upload" as shown in below screen:

    pastedimage1630593571203v1.png

    And Added the same field on form.

    Now, just to demonstrate the script behaviour i have locked the file type field when form Type is "Update". Means user editing the record after create.

    Below code written in TypeScript:

    namespace CRM{
        export namespace Library{
            export class Employee{
                onLoad(executionContext){
                    try {
                        let formContext=executionContext.getFormContext();
                        if(formContext != undefined &&
                           formContext.ui != undefined && 
                           formContext.ui.getFormType() != 1)
                        {
                            let fileUploadControl=formContext.getControl('new_fileupload');
                            if(fileUploadControl != undefined)
                            {
                                fileUploadControl.setDisabled(true);
                            }
                        }
                    } catch (error) {
                        alert(error.message);
                    }
                }
            }
        }
    }

    let empObj=new CRM.Library.Employee();

    The blue highlighted line is responsible for locking the field.

    Javascript Code:

    function onLoad(executionContext) {
        try {
            var formContext = executionContext.getFormContext();
            if (formContext != undefined &&
                formContext.ui != undefined &&
                formContext.ui.getFormType() != 1) {
                var fileUploadControl = formContext.getControl('new_fileupload');
                if (fileUploadControl != undefined) {
                    fileUploadControl.setDisabled(true);
                }
            }
        }
        catch (error) {
            alert(error.message);
        }
    }

    Output:
    pastedimage1630593965209v1.png

    Thanks,
    Pradeep.

    Please mark this as VERIFIED if it helps.

  • akersk Profile Picture
    25 on at
    RE: File input on form - how to lock? (PowerApps, model driven)

    Hi Pradeep,

    Thanks! This works :-) Much appreciated! I'll mark your reply as verified.

    Have a great day,

    - Alex.

  • Pradeep Rai Profile Picture
    5,489 Moderator on at
    RE: File input on form - how to lock? (PowerApps, model driven)

    HI Alex,

    Thanks for support.

    Regards,

    Pradeep

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 258

#2
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 178

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 142 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans