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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Upload Files to Sharep...
Power Apps
Suggested Answer

Upload Files to Sharepoint list library

(0) ShareShare
ReportReport
Posted on by 1,030
Hello everyone,
 
I have a Canvas app from which I insert documents into a library in a SharePoint list. I added a lookup column DemandeId to the library. I used this formula to insert the file and then assign a value to the DemandeId column.

The problem is that the file is inserted, but DemandeId does not take the value that is sent.
 
How can I resolve this?
 
Thank you
 
 
ForAll(
    attach_18.Attachments As Att;
 
    // 1) Upload du fichier
    With(
        {
            uploadResult: GroupesOffice365.HttpRequest(
                "https://graph.microsoft.com/v1.0/sites/fba67b00-96a3-4d24-b7e6-e300b1c2c64b/drives/b!WXum-6OWJE235uJXscLGS9CgG76TBN9Hm6mE8cKZDOhy364LkCxZRLJZjXdCCAZE/root:/"
                & Att.Name &
                ":/content";
                "PUT";
                Att.Value
            )
        };
 
        // 2) Mise à jour des métadonnées
        If(
            uploadResult.StatusCode = 201 Or uploadResult.StatusCode = 200;
 
            GroupesOffice365.HttpRequest(
                "https://graph.microsoft.com/v1.0/sites/fba67b00-96a3-4d24-b7e6-e300b1c2c64b/drives/b!WXum-6OWJE235uJXscLGS9CgG76TBN9Hm6mE8cKZDOhy364LkCxZRLJZjXdCCAZE/items/"
                & uploadResult.Response.id;
                "PATCH";
                "{'fields':{'DemandeId':" & Gallery1.Selected.ID & "}}"
            )
        )
    ))
Categories:
I have the same question (0)
  • Suggested answer
    sannavajjala87 Profile Picture
    224 Super User 2026 Season 1 on at

    Hi,

    You’re PATCHing the DriveItem URL with .../drives/{driveId}/items/{itemId} and a fields body. Custom columns (including lookup) must be updated on the ListItem fields endpoint, not the DriveItem. Also, SharePoint lookup columns require the <InternalName>LookupId property (ID of the referenced item). [learn.microsoft.com], [learn.microsoft.com]

     

    Fix (Graph):

     

    1. After upload, get the linked ListItem ID:


    2.  
     
    GET /sites/{site-id}/drive/items/{item-id}?$expand=listItem
    → listItem.id
    
     

    Then update fields:

     
    PATCH /sites/{site-id}/lists/{list-id}/items/{listItemId}/fields
    Content-Type: application/json
    
    {
      "DemandeIdLookupId": Gallery1.Selected.ID
    }
    
     

    For multi‑lookup:

     
    {
      "DemandeIdLookupId@odata.type": "Collection(Edm.Int32)",
      "DemandeIdLookupId": [1,2]
    }
    
     

    (Use the column’s internal name; single-value uses one integer, multi-value uses an array.) [stackoverflow.com], [stackoverflow.com], [stackoverflow.com]

     

    Power Apps change (your formula): Replace the second call with the ListItem fields endpoint and valid JSON:

     
    powerfx isn’t fully supported. Syntax highlighting is based on Plain Text.
    GroupesOffice365.HttpRequest(
    "https://graph.microsoft.com/v1.0/sites/<site-id>/lists/<list-id>/items/" &
    uploadResult.Response.listItem.id & "/fields",
    "PATCH",
    JSON({ DemandeIdLookupId: Gallery1.Selected.ID }, JSONFormat.Compact),
    { "Content-Type": "application/json" }
    )
     
     
     
     

    (Use the ListItem ID from uploadResult.Response.listItem.id; send JSON and Content-Type.) 

     

    Notes:

     

    • Ensure you’re using the internal name of the column (DemandeId may differ). 

    • Required permissions: Sites.ReadWrite.All. 

    • Don’t PATCH custom fields via DriveItem; Graph returns errors and ignores fields. 


    •  

    If you want, I can tailor the exact URLs using your site, list, and drive IDs.

  • gikido Profile Picture
    1,030 on at
     
    Thank you for your reply.

    I have a first question: is it possible to insert a field with the file into the library?

    If yes, I would like some details please, since I am a beginner in this field.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 993

#2
Valantis Profile Picture

Valantis 675

#3
11manish Profile Picture

11manish 545

Last 30 days Overall leaderboard