cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Saya
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
WarrenBelz
Super User
Super User

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.

prajyot
Resolver III
Resolver III

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

Saya
Frequent Visitor

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.

Hi @Saya ,

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

Saya
Frequent Visitor

@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
         }
      )
    )
)

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)

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.

Saya
Frequent Visitor

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

Helpful resources

Announcements
Ignite 2022

WHAT’S NEXT AT MICROSOFT IGNITE 2022

Explore the latest innovations, learn from product experts and partners, level up your skillset, and create connections from around the world.

Power Apps Africa Challenge 2022

Power Apps Africa Challenge

Your chance to join an engaging competition of Power Platform enthusiasts.

Top Kudoed Authors
Users online (3,774)