SharePoint List Attachments

Loading

Requirement: Display SharePoint list Attachments in Power apps using gallery controls

Create a SharePoint list “Attachments List”. Add Columns as shown in below:

  • Title- Single line of text column
  • Category- Choice column (Personal, Work)
  • Add ID, Attachments from Hide/ Show columns
SharePoint list Attachments

Create a Blank Canvas app, Add data source to the application. Note the below code and click on Run on Start. Set a variable to the app.

App OnStart Property: Set(varFormStatus, "View");Set(varUser, User())

Now add vertical gallery to the screen and add data source to it. And add Label and TextInput to the screen and write the below codes

Gallery OnSelect Property: 
Set(varFormStatus,"View")

TextInput Default Property :
Gallery9.Selected.Title

Now Add Trash Icon to remove the item from the gallery and on next arrow icon to set the form if the item selected in gallery should display on form. write the below code on

OnSelect Property : 
NextarrowIcon-   Set(varFormStatus, "View")    
TrashIcon- Remove('Attachments list' , ThisItem)

Add Edit form to the screen, form to display the selected item in gallery

On Item Property: 
If(
    varFormStatus = "New", Defaults('Attachments list'),
    varFormStatus = "View" , Gallery13.Selected,
    varFormStatus = "Edit" , Gallery13.Selected
)

On DefaultMode Property: 
If(
    varFormStatus= "New", FormMode.New,
    varFormStatus= "View",FormMode.View,
    varFormStatus= "Edit", FormMode.Edit
)

Add SubGallery on Gallery and insert image on it.

On Items Property : ThisItem.Attachments

Now Make the selected item with the color using TemplateFill Property

If(ThisItem.IsSelected, Color.LightBlue, RGBA(0,0,0,0))

Now create a collection to the application. Select Datacard add the below code and Add one more Gallery to the screen place it at right bottom corner, and select collection and add to it.

OnAddFile and OnRemoveFile Property: 
ClearCollect(TempAttachmentsCol, DatacardValue12.Attachments)

On SubGallery and Gallery3, select an Image on image write the below code

On Image Property: 
ThisItem.value

Now Add 3 Icons to the screen “Add icon”, “Edit icon”, “Save icon”.

Add Icon - OnSelect Property: 
Set(varFormStatus, "New"); NewForm(Form3); Clear(TempAttachmentCol)

Edit Icon- OnSelect Property :
Set(varFormStatus, "Edit")

Save Icon- OnSelect Property: 
If(varFormStatus ="New",

//Patch the Title and the Choice and the get the list ID
Set(TempCol, Patch('Attachments list',Defaults('Attachments list'), {Title:TextInput3.Text}));
//Update with Patch function the attachments and the choices
Patch('Attachments list',LookUp('Attachments list', ID=TempCol.ID),
{
}, Form3.Updates);
//Set forms to view mode
Set(varFormStatus, "View"),
varFormStatus = "Edit" , SubmitForm(Form3))

//Reset values
;Concurrent(
ResetForm(Form3), 
Reset(TextInput3)
)

Now Save and Preview the application, select item in gallery it displays on Edit form. user can also Remove the item from gallery. And click on Add icon and add new item on form and the item added displays on gallery3 the attachments user were added. And Edit the item already added to the gallery then click on Save. Now check on SharePoint List the items were added successfully along with attachments.

SharePoint List Attachments

Leave a Reply

Your email address will not be published. Required fields are marked *