Power Apps Exchange

Please login or click SIGN UP FOR FREE to create your PowerAppsUG account to join this user group.
Expand all | Collapse all

Attachment in Form Control, Patch Form, and other fields to SPO list

  • 1.  Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 02, 2020 08:09 PM

    Hello all,

    I've been struggling to make this happen for some time.  So, one it just can't be done or two I'm just missing something.

    What I'm after and been trying to do is take a Form control that is linked to a SharePoint list with various columns.  With the control form the only piece want to utilize at this time is the attachment control inside the form control.  Next I have some other controls and items outside of the form control that I want to patch into the same SharePoint list that the form control is tied to.

    End result is once I have a user hit a button for submit that it would submit the form control + collect + patch all the information into that one SharePoint list in one row.

    This might seem a strange ask but I've found it for some complex builds easier to utilize building those items outside of a form control to allow better flexibility.  I appreciate this communities insight if there is a way to do what I have been trying to accomplish, but just couldn't get it to work.



    ------------------------------
    Craig
    ------------------------------


  • 2.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 03, 2020 03:52 AM
    Hello Craig,

    Couple of months ago I have just created the same kind of PowerApp and it worked well for me, so I can tell you it works :). What are exactly you challenges ?

    Best regards,

    ------------------------------
    Alaa Bitar
    Consultant
    Serial Sa
    ------------------------------



  • 3.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 03, 2020 09:35 AM

    @Alaa Bitar thank you for willing to share and help.

    Where I'm hung up on is I understand the following for those items outside of the form control when my submit button is clicked:

    Collect(collection name, {Title: txtname.text, Comments: txtcomments.text});

    Patch(SharePoint List name, collection name​);
    Clear(collection name);
    Navigate(screen,None)

    What I'm stuck on is how to combine write it to include that submit form and take my above to make sure it gets written all to the same row in the SharePoint list name when the button is clicked.

    Again appreciate the assist.



    ------------------------------
    Craig
    ------------------------------



  • 4.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 04, 2020 02:48 AM
    Hello Craig,

    Well basically when you submit a form you have this LastSubmit property from wicht you can get the ID of the last submited item, then in your patch you do a lookup to get that element and update it with you collection. So your submit button onselect property should look like this :
    Submit(Form_Name);Collect(collection_name, {Title: txtname.text, Comments: txtcomments.text});Patch(SharePoint_List_name, Lookup(SharePoint_List_name, ID = Form_Name.LastSubmit:ID),collection_name​);Clear(collection name);Navigate(screen,None)

    Best regards,


    ------------------------------
    Alaa Bitar
    Consultant
    Serial Sa
    ------------------------------



  • 5.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 04, 2020 11:01 AM

    @Alaa Bitar thank you for supplying that function.  I'm running into a little snag with that function supplied.

    SubmitForm(Form1);
    Collect(colloose,{Title:TextInput1.Text});
    Patch('AttachCollect',Lookup('AttachCollect',ID=Form1.LastSubmit:ID),colloose)

    What I'm getting when I type this on my button in onselect is following errors:
    for the = sign I get "Invalid Argument type
    for the : sign I get "Unexpected characters the formula contains "ParenClose" where "Colon" is expected and Unexpected characters.  Characters are used in the formula in an unexpected way."

    Again appreciate you time and help.  Am I missing something in the function formula you supplied or has something changed?



    ------------------------------
    Craig
    ------------------------------



  • 6.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 07, 2020 01:47 AM
    Hello Craig,

    Sorry typing mistake it is Form_Name.LastSubmit.ID and not Form_Name.LastSubmit:ID
    Can you try it and let me know if it works ?

    Best regards,


    ------------------------------
    Alaa Bitar
    Consultant
    Serial Sa
    ------------------------------



  • 7.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 07, 2020 02:39 PM

    @Alaa Bitar thank you again for the assist in this.  So, we are a step closer but still got an error message for the following:

    SubmitForm(Form1);
    Collect(colloose,{Title:TextInput1.Text});
    Patch('AttachCollect',Lookup('AttachCollect',ID=Form1.LastSubmit.ID),colloose) ​

    The error I get for the Patch function section is on the  ,colloose  It states "Invalid argument type (Table).  Expecting a Record value instead.  The function "Patch" has some invalid arguments."

    Am I missing something or a step not aware of?  Thank you again Alaa.



    ------------------------------
    Craig
    ------------------------------



  • 8.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 08, 2020 01:09 AM

    @Alaa Bitar  I'm hoping you have the fix.  While I was waiting I was doing some trial and error on things and came up with this and it works, but not to thrilled on how long it takes to run the attachment piece on submit.  I find that it captures the column information right away but just to get the attachment added does take some time.  I did find I needed to not use the default Title column and just created me another column for title.

    This is what I got for the submit button on select:

    Patch(SharePoint list name, Defaults(SharePoint list name),{Title2: Textname.Text, SLOT: Textname.Text, Choice: Dropdown.Selected}, Form1.Updates) ​

    Look forward to your reply and what you have found where the adjustment is needed in your solution provided.



    ------------------------------
    Craig
    ------------------------------



  • 9.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 09, 2020 08:40 AM
    @Alaa Bitar just checking back in with you to see with your solution where it was still hung up if I was missing anything.  Always nice to have various options that work and wanted to also see your solution in action. ​

    ------------------------------
    Craig
    ------------------------------



  • 10.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 10, 2020 02:09 AM
    Hi Craig,

    I tried to reproduce your problem without any luck. I don't have any speed issues. Do you have a lot of element in your sharepoint list ?

    Best regards,

    ------------------------------
    Alaa Bitar
    Consultant
    Serial Sa
    ------------------------------



  • 11.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 09, 2020 11:04 AM
    Hi Craig,
    Just a little hint here... The code you have after your SubmitForm() should be moved to your form's OnSuccess event. Ortherwise you will try to patch a record that doesn't exist if the SubmitForm() goes sideways.
    The best practice when it comes to: I submit a form and right after that I want to update the item I just created is to place that update operation in the OnSuccess event of the form.​
    Also be aware that inside the OnSuccess event of your form, never access your datacards directly as they've already been reset after the SubmitForm() has ran. So if you need to access some of your datacard's content inside the OnSuccess event, you should use variables to store that content right before your SubmitForm() and then use it inside the OnSuccess event.
    😊

    ------------------------------
    EMMANUEL GALLIS
    Power Platform Consultant
    France
    ------------------------------



  • 12.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 09, 2020 07:12 PM

    @EMMANUEL GALLIS  I tried to follow and separated this out: 

    SubmitForm(Form1);
    Collect(colloose,{Title:TextInput1.Text});
    Patch('AttachCollect',Lookup('AttachCollect',ID=Form1.LastSubmit.ID),colloose) ​

    but it ended saving two rows one with attachment and the other with the collection in the SharePoint list.

    What I did find if I use the following:

    Patch(SharePoint list name, Defaults(SharePoint list name),{Title2: Textname.Text, SLOT: Textname.Text, Choice: Dropdown.Selected}, Form1.Updates) ​

    on the On Select of my button named Submit it does exactly what I'm after and that is take all the attachments that were attached in the form control attachment piece and then take all the fields I have hand built outside of the form control and tie them all together into one row in a SharePoint list.

    So, far haven't found a downside yet on this solution with help here from @Alaa Bitar and some trial and error on my end.   ​

    @EMMANUEL GALLIS please let me know if or what I might of missed from your hint.  Thank you.​​

    ------------------------------
    Craig
    ------------------------------



  • 13.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Gold Contributor
    Posted Dec 10, 2020 04:39 AM
    Hi Craig,
    Even though I understand what your are trying to do (use the form only for the attachments and have the other fields outside the form) I don't see why you want to proceed this way.
    Why would you say, in your original post, that you have more flexibility if your SharePoint list's fields are outside the form?
    Come on, challenge me on this! 😉
    It would be so much simpler to have both fields and attachements all together inside the form: you just do a SubmitForm() and that's it! Not Patch() needed.

    Anyway, about your Patch() function, you should know that there are only two ways to structure a Patch() call:
    • change only one record:
    • change a set of records:
    In your call to the Patch() function you kind of do a mix of these two which is not possible:

    The LookUp() part points to a specific unique record but at the same time in the last parameter you specify a collection (even though there's only on record in it, which might work but is not a best practice).
    Your patch should be more like this:
    Patch('AttachCollect', Lookup('AttachCollect',ID=Form1.LastSubmit.ID), {Title:TextInput1.Text})​

    Waiting for your reply... 😉

    Have a nice day,

    Emmanuel


    ------------------------------
    EMMANUEL GALLIS
    Power Platform Consultant
    France
    ------------------------------



  • 14.  RE: Attachment in Form Control, Patch Form, and other fields to SPO list

    Bronze Contributor
    Posted Dec 10, 2020 09:07 AM
    Edited by Craig Gregory Dec 10, 2020 07:13 PM

    @EMMANUEL GALLIS  appreciate your response and insight. 

    For the debate around to form control or not form control I have found personally easier to deal with function writing with items outside of the form controls, the ability and easy to layout the screens to my clients specs, and when client wants changes easier to add/subtract without effecting a whole form control.  I know it might not seem conventional, but the lovely part of this technology is there are different ways to get to the end goal.  Don't get me wrong I have used form controls when I see they fit into a simplistic solution, but if I'm dealing with more complex builds and needs that likely will have changing specs I tend to free form build.  Not sure if that was a strong challenge, my strength is not debating, woo and harmony :-).  I do appreciate what you bring to the table and tested out the Patch piece you provided and works nicely.  I'm proud we have an awesome community around the globe and I have got to know many of you over the years via media and the SharePoint Conferences in Vegas.  



    ------------------------------
    Craig
    ------------------------------