cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hello, 

I have the following requirement. I have a powerapp page that submits selected social media platforms where a user has agreed to share a message on, as shown below.

So far i have successfully managed to capture and track all messages shared on the different platforms by the different users on my first SharePoint List (SocialMedia SharedBy) 

 

My problem lies in capturing the number of times a message has been shared on a particular social media platform. This needs to be done in the second sharepoint list (Platform Message Counter) which is dedicated on storing the counter for each message on each social media platform shared. 

 

att1.PNGlist1.PNGlist2.PNG

This is what i have so far on my onSelect property of my Submit Button in powerapps. 

 

 

ForAll(
    ComboBox2.SelectedItems,
    Patch(
        'SocialMedia SharedBy',
        Defaults('SocialMedia SharedBy'),
        {
            MsgID: BrowseGallery1.Selected.ID,
            SharedBy: User().FullName,
            'Other Shared': Value
        }
    );
    If(
        IsBlank(
            LookUp(
                'Platform Message Counter',
                MessageID = BrowseGallery1.Selected.ID
            )
        ),
        Patch(
            'Platform Message Counter',
            Defaults('Platform Message Counter'),
            {
                MessageID: BrowseGallery1.Selected.ID,
                'Platform Shared': Value,
                Counter: 1
            }
        )
    )
);

 

 

Unfortunately when i try to include the patch for updates incase a message and platform already exists and i only need to update the counter column, i get the error that "this function cannot be invoked within forall".  Please help. 

8 REPLIES 8
Highlighted
Super User III
Super User III

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hi @Saya ,

I assume you are referring to something like this?

ForAll(
   ComboBox2.SelectedItems,
   Patch(
      'SocialMedia SharedBy',
      Defaults('SocialMedia SharedBy'),
      {
         MsgID: BrowseGallery1.Selected.ID,
         SharedBy: User().FullName,
         'Other Shared': Value
      }
   );
   If(
      IsBlank(
         LookUp(
            'Platform Message Counter',
            MessageID = BrowseGallery1.Selected.ID
         )
      ),
      Patch(
         'Platform Message Counter',
         Defaults('Platform Message Counter'),
         {
            MessageID: BrowseGallery1.Selected.ID,
            'Platform Shared': Value,
            Counter: 1
         }
      ),
	  Patch(
         'Platform Message Counter',
         {MessageID: BrowseGallery1.Selected.ID},
         {  'Platform Shared': Value,
            Counter: Counter+1
         }
      )
   )
)

then try this

ForAll(
   ComboBox2.SelectedItems,
   Patch(
      'SocialMedia SharedBy',
      Defaults('SocialMedia SharedBy'),
      {
         MsgID: BrowseGallery1.Selected.ID,
         SharedBy: User().FullName,
         'Other Shared': Value
      }
   );
   If(
      IsBlank(
         LookUp(
            'Platform Message Counter',
            MessageID = BrowseGallery1.Selected.ID
         )
      ),
      Patch(
         'Platform Message Counter',
         Defaults('Platform Message Counter'),
         {
            MessageID: BrowseGallery1.Selected.ID,
            'Platform Shared': Value,
            Counter: 1
         }
      ),
      UpdateIf(
         'Platform Message Counter',
         MessageID = BrowseGallery1.Selected.ID,
         {
            'Platform Shared': Value,
            Counter: Counter+1
         }
      )
   )
)

 

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.

Highlighted
Resolver II
Resolver II

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

UpdateIf() or Update will be helpful , as you are increasing the counter by 1.

Highlighted
Frequent Visitor

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hi @WarrenBelz thank you for your response. I have tried your suggestion, unfortunately, now i am getting this error on the UpdateIf function: Invalid argument type (table). Expecting a record value instead.

Highlighted
Super User III
Super User III

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hi @Saya ,

Where are you getting this error? I also just noticed you have MsgID and MessageID in different places, which one is correct?

Highlighted
Frequent Visitor

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

@WarrenBelz MsgID is for 'SocialMedia SharedBy' sharepoint list while MessageID is for 'Platform Message Counter' sharepoint list

 

I get the error, when i add the UpdateIf function after the Patch function.

 

ForAll(
    ComboBox2.SelectedItems,
    Patch(
        'SocialMedia SharedBy',
        Defaults('SocialMedia SharedBy'),
        {
            MsgID: BrowseGallery1.Selected.ID,
            SharedBy: User().FullName,
            'Other Platforms Shared': Value
        }
    );
    If(
        IsBlank(
            LookUp(
                'Platform Message Counter',
                MessageID = BrowseGallery1.Selected.ID
            )
        ),
        Patch(
            'Platform Message Counter',
            Defaults('Platform Message Counter'),
            {
                MessageID: BrowseGallery1.Selected.ID,
                'Platform Shared': Value,
                Counter: 1
            }
        ),UpdateIf(
         'Platform Message Counter',
         MessageID = BrowseGallery1.Selected.ID,
         {
            'Platform Shared': Value,
            Counter: Counter+1
         }
      )
    )
)
Highlighted
Super User III
Super User III

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

OK @Saya ,

What line of the code is showing the error?

This is very strange as I have simply taken your existing code and tested the part 

MessageID = BrowseGallery1.Selected.ID

for an exiting record. The UpdateIf() syntax is valid (although your error seems to be referring to either testing a table)

Highlighted
Super User III
Super User III

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hi @Saya ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

 

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.

Highlighted
Frequent Visitor

Re: Update Counter Column on Sharepoint List B Based on Combobox Selected Value in Sharepoint List A

Hi @WarrenBelz , unfortunately i have been completely stuck. Still trying to figure out another workaround for achieving the same goal.

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,858)