I recently worked on a client task where I needed to patch the attachments from a Power Apps modern form to a SharePoint list. Additionally, some validations and conditions exist when updating any file or image on the list.
In this article, I will tell you how to patch attachments to the SharePoint list attachment column based on some conditions.
Power Apps Patch Attachments to SharePoint List
A SharePoint list called Unit Test contains four columns with different data types. Such as:
Column | Data type |
---|---|
Title | By default single line of text |
Status | Choice [Pass, Fail, N/A] |
Test Notes | Multi-line text |
Attachment | Attachments |
I have added some items, except the Test Notes and Attachments, to this list. I want to update these two fields using Power Apps.

In Power Apps, there is a gallery control and a Modern form. When the user selects any specific item, the right side of the form displays the details of the particular item. Also, user can update their record by using the save button. The save button won’t be visible until the edit icon is clickable.

Also, some conditions must be checked while attaching the files/videos and clicking the save button. Such as:
Case – 1:
If Status = Fail, then the Attachments field will be mandatory.
Case – 2:
If Status = Fail, the User must fill in the Test Notes, which should take only 10 characters.
Case – 3:
If Status ❌ Fail, then the attachment field will not be mandatory, and the test notes validation will also not be applicable here. That means it will simply take your value and update the specific item in the SharePoint list.
Case – 1 & Case – 2:
Here, in the screenshot below, you can see that whenever the user selects the Status as Fail and fills in the Test Notes, it shows the validation error under the notes and the attachments field mandatory.

The validation error is not shown whenever the user fills the Test Notes with 10 characters. Also, he/she can upload any file/video in the attachments. If no file is there and tried to update the item, then the item will not update, and also, it’ll show the validation error for attaching the file.
Once the file has been attached and clicked on save, it’ll display a success popup message on the screen.

Go to the SharePoint list and refresh it once. The item has been updated along with the Test notes and Attachments below.

Case – 3:
Suppose I choose the Status as Pass or any other values apart from the Fail; then that time, it won’t show any validation error, and the attachments will not be mandatory. So we can update the items without any conditions.

You can see the item has been updated in the SharePoint list.

Patch Attachments to SharePoint List in Power Apps
Case – 1: [Solution]
If Status = Fail, then the Attachments field will be mandatory.
Select the Attachment Datacard and set its Required property to the code below:
If(
!IsBlank(DataCardValue12.Selected.Value),
If(
DataCardValue12.Selected.Value = "Fail",
true,
false
),
false
)
Where,
DataCardValue12 = Status field name

Case – 2: [Solution]
If Status = Fail, the User must fill in the Test Notes, which should take only 10 characters.
Select the Test Notes field and set its Value property to the code below:
LookUp('Unit Test',ID=Gallery1.Selected.ID,'Test Notes')
Where,
Gallery1 = Gallery control

To validate the Test Notes field, write the code below on its OnChange property as:
OnChange = UpdateContext(
{
HasFirstNameInput: true,
// Track that the user has started typing
IsFirstNameInvalid: If(
DataCardValue12.Selected.Value = "Fail",
Len(Self.Value) < 10
)
}
)
HasFirstNameInput, IsFirstNameInvalid = Context variable name

To display the error message under the Test Notes field, select the error message field and set its Text property to the formula below:
Text = If(IsFirstNameInvalid,"Please enter Test Notes on failure and attach screenshot or video"," ")

Next, select the error message field and apply the variables on its Visible property:
Visible = HasFirstNameInput && IsFirstNameInvalid

Now it’s time to update all the SharePoint list’s field values and the attachments. Additionally, only the Save button will be visible once the user clicks the Edit icon; otherwise, it’ll always be in hidden mode.
To do this, we will create a Context variable on the Edit icon’s OnSelect property as:
OnSelect = UpdateContext({ varSubmit:true})
Where,
varSubmit = Variable Name

Insert a Save button and set its OnSelect property as:
OnSelect = If(
DataCardValue12.Selected.Value <> "Fail",
Patch(
'Unit Test',
LookUp(
'Unit Test',
ID = Gallery1.Selected.ID
),
{
'Test Notes': DataCardValue11.Value,
Status: {Value: DataCardValue12.Selected.Value}
},
Form1.Updates
);
UpdateContext(
{
varSubmit: false,
varSavePopUp: true
}
);
,
If(
!IsBlank(DataCardValue11.Value),
If(
DataCardValue12.Selected.Value = "Fail" && !IsFirstNameInvalid,
If(
DataCardValue12.Selected.Value = "Fail" && !IsAttached,
Patch(
'Unit Test',
LookUp(
'Unit Test',
ID = Gallery1.Selected.ID
),
{
'Test Notes': DataCardValue11.Value,
Status: {Value: DataCardValue12.Selected.Value}
},
Form1.Updates
);
UpdateContext(
{
varSubmit: false,
varSavePopUp: true
}
);
,
Notify(
"Please attach files!",
NotificationType.Error
)
),
Notify(
"Please provide Test Notes on failure more than 10 characters!",
NotificationType.Error
)
),
Notify(
"Please provide Test Notes!",
NotificationType.Error
)
)
);
Refresh('Unit Test');
Where,
- DataCardValue12 = Status field name
- DataCardValue11 = Test Notes field name
- Form1 = Edit form name
- varSavePopUp = This is the variable I created for a success pop-up message. If the code executes fine, the values will update in the SharePoint list, and the user can see a pop-up message.

Finally, save, publish, and preview the app. Test this, including the status, test notes, and attachment value. All the field values will be updated in the SharePoint list.
I hope this article finds you very helpful. This way, we can patch attachments to the SharePoint list in Power Apps, including specific conditions.
Moreover, you may like some more Power Apps articles:
- Replace Current User Email With Anonymous Email in Power Apps
- Pagination in Power Apps Gallery
- Set Default Value in Power Apps Modern Radio Button Control
- Power Apps Login Page Forgot Password Feature
- Show the Current Logged In User in a Combo Box On a Power Apps Modern Form
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com