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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Lock attachment(file d...
Power Apps
Answered

Lock attachment(file data type) fields based on business process flow stage

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello team,

I am looking to find a method to lock/unlock attachment(file data type) fields based on business process flow stages.

radusitaru_0-1655887731508.png


I know that file columns cannot be locked/unlocked with business rules.

Is JavaScript the only solution in this case?

If so, could you please help with a code template for that?

Regards,




I have the same question (0)
  • AhmedSalih Profile Picture
    6,678 Moderator on at

    @radusitaru , I had similar scenario to lock an attachment field but I wasn't verifying against BPF stage, it was against Employment status field value. Here is my code for that purpose.

    function setFieldDisabled(executionContext) {
     var formContext = executionContext.getFormContext();
     var employmentStatus = formContext.getAttribute('EmploymentStatus').getValue();
     var attachResume = formContext.getControl('ResumeAttachement');
    
    
     if (employmentStatus == 'New' ) 
     {attachResume.setDisabled(false);} 
     else
     {attachResume.setDisabled(true);} 
    
    }

     

    Regards,
    Ahmed
    If my reply helped you, please give a 👍. And if it has solved your issue, please consider Accept it as the Solution to help other members in the community find it more.

  • Verified answer
    radusitaru Profile Picture
    Microsoft Employee on at

    Hello Ahmed. Your reply helped me a bit, but here is the code that made it work:

    //Main function to lock attachment field
    function cra5a_LockAttachment(executionContext) {
    
     //Get context
     var formContext = executionContext.getFormContext();
    
     //Trigger onStageChange
     formContext.data.process.addOnStageChange(onStageChange);
    
     //Trigger onLoad
     formContext.ui.addOnLoad(onLoad)
    
    
    }
    //Same function as main, but triggered onStage change
    function onStageChange(executionContext){
    
     var formContext = executionContext.getFormContext();
     var attachment1 = formContext.getControl('cra5a_file');
     var attachment2 = formContext.getControl('cra5a_file2');
     var stageName = formContext.data.process.getSelectedStage().getName();
    
     if (stageName == '1. DCA Specialist Input') 
     {attachment1.setDisabled(false);} 
     else
     {attachment1.setDisabled(true);} 
    
     if (stageName == '4. Calibration Input') 
     {attachment2.setDisabled(false);} 
     else
     {attachment2.setDisabled(true);} 
    }
    
    //Same function as main, but triggered onStage change
    function onLoad(executionContext){
    
     var formContext = executionContext.getFormContext();
     var attachment1 = formContext.getControl('cra5a_file');
     var attachment2 = formContext.getControl('cra5a_file2');
     var stageName = formContext.data.process.getSelectedStage().getName();
    
     if (stageName == '1. DCA Specialist Input') 
     {attachment1.setDisabled(false);} 
     else
     {attachment1.setDisabled(true);} 
    
     if (stageName == '4. Calibration Input') 
     {attachment2.setDisabled(false);} 
     else
     {attachment2.setDisabled(true);} 
    }



  • Gras8 Profile Picture
    2 on at

    For me this is not working the disabled false when the status is closed.

    Are there any way to enabled it?

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard