cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
stayinginsync
Advocate II
Advocate II

Patch Both LookUp and Attachments to SharePoint. Only one or the other works, not both.

Issue: Unable to Patch SharePoint Site with both LookUp values AND Attachments.  Only one, or the other works, but not both. 

 

Everything in the code below, works to Patch my Lookup fields in SharePoint from the PowerApps Form:

 

SharePointIntegation > OnSave

 

 

Patch('SPList',
          Defaults('SPLIst'),

          Column1: textbox.Text,
          Column2: textbox.Text,
          Column3: {
              '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
               Id: combobox1.Selected.ID,
               Value: combobox2.Selected.Title
               },
          Column4: {
                '@odata.type': #Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                 Id: ddVehicle.Selected.Id,
                 Value: ddVehicle.Selected.Value
                    },
           );
      ResetForm(SharePointForm1); 
      RequestHide() 

 

 

I found this thread here, and the suggestion worked to add the attachments to the SharePoint item BUT, now the LookUp columns are empty:

 

 

 SharePointForm1.Updates

 

 

Here is the final version of the code I'm using

 

 

Patch('SPList',
          Defaults('SPLIst'),

          Column1: textbox.Text,
          Column2: textbox.Text,
          Column3: {
              '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
               Id: combobox1.Selected.ID,
               Value: combobox2.Selected.Title
               },
          Column4: {
                '@odata.type': #Microsoft.Azure.Connectors.SharePoint.SPListExpandedReference",
                 Id: ddVehicle.Selected.Id,
                 Value: ddVehicle.Selected.Value
                    },
          SharePointForm1.Updates
      );
      ResetForm(SharePointForm1); 
      RequestHide() 

 

3 ACCEPTED SOLUTIONS

Accepted Solutions
WarrenBelz
Super User
Super User

Hi @stayinginsync ,

Try the other way around - you also have Id instead of ID and you do not need the odata reference any more

Patch(
   'SPList',
   Defaults('SPList'),
   SharePointForm1.Updates
   Column1: textbox.Text,
   Column2: textbox.Text,
   Column3: 
   {
      Id: combobox1.Selected.ID,
      Value: combobox2.Selected.Title
   },
   Column4: {
      Id: ddVehicle.Selected.ID,
      Value: ddVehicle.Selected.Value
   },
);
ResetForm(SharePointForm1); 
RequestHide()

I am also assuming here that both combo boxes have Items of

Choices(SPList.LookupFieldName)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

View solution in original post

Hi @stayinginsync ,

In the DefaultSelectedItems, try the following

ComboBox1

{SPLookupColumn1:ThisItem.SPLookupColumn1}

ComboBox2

{Title:ThisItem.SPLookupColumnA}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

View solution in original post

Hi @stayinginsync ,

I will take a guess here you are writing back to a Choice or Lookup field - if so (you have redacted the values, so I will use numbers)

{Value1:ThisItem.Value2.Value}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

View solution in original post

14 REPLIES 14
WarrenBelz
Super User
Super User

Hi @stayinginsync ,

Try the other way around - you also have Id instead of ID and you do not need the odata reference any more

Patch(
   'SPList',
   Defaults('SPList'),
   SharePointForm1.Updates
   Column1: textbox.Text,
   Column2: textbox.Text,
   Column3: 
   {
      Id: combobox1.Selected.ID,
      Value: combobox2.Selected.Title
   },
   Column4: {
      Id: ddVehicle.Selected.ID,
      Value: ddVehicle.Selected.Value
   },
);
ResetForm(SharePointForm1); 
RequestHide()

I am also assuming here that both combo boxes have Items of

Choices(SPList.LookupFieldName)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

@WarrenBelz 

 

Item #1 - Thanks for the feedback.  That worked.  

 

Item #2 - the "dd" is a dropdown, not a combobox.  If I change it from Id to ID, the whole thing goes red.

 

Item #3 - To answer your question,  no I'm not using Choices, because I get this error: stayinginsync_0-1647801786167.png

This may, or may not, help.  The code is part of a cascading drop-down list.

 

  • ComboBox1.Items = 

 

 

Sort(SPList,SPLookupColumn1,Ascending)

 

 

  • ComboBox2.Items = 

 

 

SortByColumns(Filter(SPList2, SPLookupColumn1 = combobox1.Selected.Title),"Title",SortOrder.Ascending)

 

 

  • Textbox1
  • Textbox2

 

 

Concatenate(combobox1.Selected.field_1," ", combobox2.Selected.field_3," ", Textbox1.Text)

 

 

It works, but if there is a good reason I should use "Choices" instead of this, I'm open to hearing it, and suggestions on how to fix the implementation for improvement.

 

Item #4 - And, if I may ask a follow-up, this is great for the SharePointFormIntegration.OnSave, but I cannot figure out what to put in the OnView and OnEdit to display the Lookup items selected in SharePoint.   Do I need to do some kind of a reverse Patch(); ???  {{if you need me to create a new post for this item so I can resolve item #1, and then you get credit for solving items 3 & 4 separately, I'd be happy to do so, just let me know}}

 

  • OnView & OnEdit are using:

 

 

Set( selectedItem,
    SharePointIntegration.Selected );

 

 

 

Thanks in advance.

Twitter - @technomensch

Hi @stayinginsync ,

#1 - good to see it works as this was the question you posted

#2 - if it works, leave it alone (I  could not see your data)

#3 - as above and was just making a likely assumption - what you have does not suit Choices()

#4 - this should resolve on the form (the Lookup in the control) - what is it you are trying to do that is not working ?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

@WarrenBelz 

 

When I select the item from my SharePoint list, and hit EDIT, or click on it to view, the two comboboxes are not populated by the LookUp values.  The comboboxes are empty.  When I say empty, I mean they are not populated with the data written to the column when the new item was saved.  The other fields, however, are populated as expected.

 

Thank you in advance.

Twitter- @technomensch.

Hi @stayinginsync ,

Please supply (in Text) for the two Combo Boxes

  • The Items of the two Combo Boxes
  • The DefaultSelectedItems of these
  • The name and type of field it is writing to

 

@WarrenBelz 

 

SPList1 = SPLookupColumn1 (Text Column on SharePoint)

SpList2 = SPLookupColumnA (Text Column on SharePoint)

 

  • ComboBox1 (Items)
Sort(SPList1,SPLookupColumn1,Ascending)
  • ComboBox1 (DefaultSelectedItems)
Parent.Default
  • CombBox2 (Items)
SortByColumns(Filter(SPList2, SPLookupColumnA = combobox1.Selected.Title),"Title",SortOrder.Ascending)
  • CombBox2 (DefaultSelectedItems)
Parent.Default

 

Hi @stayinginsync ,

In the DefaultSelectedItems, try the following

ComboBox1

{SPLookupColumn1:ThisItem.SPLookupColumn1}

ComboBox2

{Title:ThisItem.SPLookupColumnA}

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

@WarrenBelz 

 

Thanks.  I had it working ONCE.  (One of the few things I hate about this feature is there is no revision history to revert back to).  Then I tried to make some additional changes to see if I could also leverage the ViewForm to make just the View ReadOnly, but now I broke both and can't get them to work again.  Can you verify which of the following the SharePointIntegration OnEdit and OnView should be:

 

  • Option #1

 

Set( selectedItem,
    SharePointIntegration.Selected );

 

 

  • Option #2 - OnView

 

Set( selectedItem,
    SharePointIntegration.Selected );
ViewForm(SharePointForm1);

 

 

  • Option #2 - OnEdit

 

Set( selectedItem,
    SharePointIntegration.Selected );
EditForm(SharePointForm1);

 

 

  • Option #3 - OnView

 

ViewForm(SharePointForm1);
Set( selectedItem,
    SharePointIntegration.Selected );

 

 

  • Option #3 - OnEdit

 

EditForm(SharePointForm1);
Set( selectedItem,
    SharePointIntegration.Selected );

 

 

  • Option #4 - OnView
Set( selectedItem,
    SharePointIntegration.Selected );
SharePointForm1.DisplayMode.View;

 

  • Option #4 - OnEdit
Set( selectedItem,
    SharePointIntegration.Selected );
SharePointForm1.DisplayMode.Edit;

 

And that combobox1.Default and comboBox2.Default (not DefaultSelectedItems) should be

 

  • Option #1

 

Parent.Default

 

 or

  • Option #2

 

ThisItem.SPList

 

 

Thanks in advance.

@stayinginsync ,

The Default in Combo Boxes does nothing (I am not sure why it is there) - to display the required value, it needs to be in DefaultSelectedItems - did you try the suggestions I posted?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Visit my blog Practical Power Apps

 

 

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,480)