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 :
Power Apps - Building Power Apps
Unanswered

Upload Files to Sharepoint list library

(0) ShareShare
ReportReport
Posted on by 968
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 & "}}"
            )
        )
    ))
I have the same question (0)
  • Suggested answer
    sannavajjala87 Profile Picture
    123 on at
    Upload Files to Sharepoint list library

    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.

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

Coming soon: forum hierarchy changes

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

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 757 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 345 Super User 2025 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 251 Super User 2025 Season 2

Last 30 days Overall leaderboard