Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Form in DisplayMode New - How to save Attachments to SharePoint List

(0) ShareShare
ReportReport
Posted on by

Hi, 

I have a submit button and the OnSelect looks like so;

 

Patch(
         'SharePointList 1',
         {
                 'Component Type': ComboBox_Type.Selected,
                 'Component Name': TextInput_Name.Text
         }
);

Patch(
         'SharePointList 2',
          {
               'Component Version':TextInput_Version.Text,
               'Component Description': TextInput_Description.Text,
               'Component Name':
                {
                        Value: TextInput_Name.Text,
                        Id:
                        LookUp(
                                  'SharePointList 1',
                                  'Component Name' = TextInput_Name.Text
                         ).ID
                  }
        }, Form_Attachments.Updates
)

 

Here I am patching a new item to 'SharePointList 1' and then patching to 'SharePointList 2' using a Form in 'New' mode. In the second patch the 'Component Name' is searched for in 'SharePointList 1' and then used as the Component Name in 'SharePointList 2'. I had to do it this way as 'Component Name' is a lookup column that connects both lists.

 

My problem - After doing some research I realised that patching an Attachment to SP could be tricky. So, I followed the online advice and created a separate Form with just the Attachment property in it. I then referenced the Form in the Submit button above (Form_Attachments.Updates). but I keep getting an error saying that there is a Patch error and that the 'Component Name' is required. I guess this is because it doesn't know where to place the attachment as I am not referring to the specific item I would like to patch the attachment to.

 

I would appreciate if someone could help me with adding an attachment to a SPL when using a 'New' Form and when the target list has a required column that is of type Lookup to another list. Hope I've explained that ok.

 

Regards

Categories:
  • Verified answer
    Marty3012 Profile Picture
    Marty3012 on at
    Re: Form in DisplayMode New - How to save Attachments to SharePoint List

    Hi @FLMike - I really struggled to get it to work so I used Flow instead. I have almost got that working but need a bit of help with the last part of it, so I'm going to start another thread as its quite different to the original question. Thanks

  • Marty3012 Profile Picture
    Marty3012 on at
    Re: Form in DisplayMode New - How to save Attachments to SharePoint List

    HI @FLMike ,

     

    I included the defaults() function in the patch but get the same error. I am creating a record in the SPL and I think you are correct, I will need some kind of look up to find the record I've just created. 

     

    In the first patch I create a record in 'SharePointList 1' and then in the second patch I look up 'SharePointList 1' to find 'Component Name' and then use this name as a value in 'SharePointList 2' column 'Component Name'. This is because the 'Component Name' column in 'SharePointList 2' is a look up column. The above all works without the attachments included. Would I need a separate patch for the Attachment?

     

    Apologies as I'm struggling to explain this right.

     

    Thanks

  • FLMike Profile Picture
    FLMike 27,286 on at
    Re: Form in DisplayMode New - How to save Attachments to SharePoint List

    @Marty3012 

     

    Hi Marty,

     

    If I might first say, looking at this statement, I do not see the Default('SharePointList 1') required for patching a new record. Is this maybe just a typo in what you shared? And is why it may not be finding it and failing the second patch.

     

     

     

    Patch(
     'SharePointList 1',
     {
     'Component Type': ComboBox_Type.Selected,
     'Component Name': TextInput_Name.Text
     }
    );

     

     

     

    Patch(
     'SharePointList 1',Defaults('SharePointList 1'),
     {
     'Component Type': ComboBox_Type.Selected,
     'Component Name': TextInput_Name.Text
     }
    );​

     

     

    Also for your second patch, I do not see a LookUp to the record you want to patch (or is this a create?)


    If you like my answer, I would really appreciate if you please Mark it as Resolved, and give it a thumbs up, so it can help others

    Cheers

    Thank You
    Michael Gernaey MCT | MCSE | MCP | Self-Contractor| Ex-Microsoft
    https://gernaeysoftware.com
    LinkedIn: https://www.linkedin.com/in/michaelgernaey

     

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

End of Year Newsletter…

End of Year Community Newsletter…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #11 New Opportunities…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,609

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,420

Leaderboard