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 III
Super User III

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 II
Resolver II

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
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,665)