cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
fbxiii
Level: Powered On

UpdateIf issue

I am building an App where the user can leave comments against an item posted a notice board.  When a comment is first added, I am updating a 'Has_Comments' flag in my list to True.

 

If the user deletes their comment and then leaves the item without comments, I am trying to set the flag back to False but it doesnt seem to work.  I've tried the updates in different events on different pages but it never updates the list.

 

Can anyone see what I am doing wrong?

 

My update if looks like this:  If(CountRows(Gallery3.AllItems) = 0,UpdateIf('Notice Board App',Text(ID) = DataCardValue7.Text,{ Has_Comments: false }));


Accepted Solutions
Meneghino
Level 10

Re: UpdateIf issue

Thank you for clarifying.

I would suggest one of two things:

 

1) Set the Visible property to something like this:

!IsEmpty(Filter(CommentsList, ID = ThisItem.XXX))

You can always improve performance if needed using the advice in this blog post

 

2) Update the flag using Flow instead, this will be more robust and improve performance of the app


All Replies
Meneghino
Level 10

Re: UpdateIf issue

Two things come to mind:

1) Delegation issues if you have > 500 records

 

2) Try this equivalent syntax

If(CountRows(Gallery3.AllItems) = 0,UpdateIf('Notice Board App', ID = Value(DataCardValue7.Text),{ Has_Comments: false }))

or alternatively a Patch type syntax

If(CountRows(Gallery3.AllItems) = 0, Patch('Notice Board App', {ID: Value(DataCardValue7.Text)}, {Has_Comments: false}))

 

fbxiii
Level: Powered On

Re: UpdateIf issue

I don't have more than 500 records in my list but that is something I will bear in mind if it happens.

 

Using the Patch function seemed to work to remove the flag, thanks.

 

The interesting thing is, the initial update to set the flag to Yes doesn't work now!

Meneghino
Level 10

Re: UpdateIf issue

Patch is always good.  Glad it worked.

fbxiii
Level: Powered On

Re: UpdateIf issue

Yes, Patch got me a step closer but now confusion has kicked in again because I can't set the Flag to true when the user adds a comment now.  I can't put my finger on it but things don't seem to be consistent all the time in PA.

 

Could there be a delay before the Record is added/removed to the Comments List and therefore the Count = 0 isn't registering?

 

 

Meneghino
Level 10

Re: UpdateIf issue

Yes, could be.  Difficult to comment since I do not know the business logic behind the need for the count.  Maybe it can be obviated.

fbxiii
Level: Powered On

Re: UpdateIf issue

The requirement is for a Icon to show on the initial Browse screen when comments are present against a Posted item.  If the last comment is deleted, the Flag should be reset to False so the icon doesn't appear visible.

 

To achieve this I am trying to update the 'Has_Comments' Flag to true when the user clicks on the Submit button on the Add/Edit comments form.

 

Submit button OnSelect :=

 

If(CountRows(Gallery3.AllItems) = 0, Patch('Notice Board App', {ID: Value(DataCardValue15.Text)}, {Has_Comments: true}));
SubmitForm(EditForm3);
Navigate(DetailTabScreen,None)

 

There is a Delete button on the View comments screen which tries to check if there are no longer any Comments associated to the Item and resets the Flag if none are found.

 

Delete button OnSelect :=

 

Remove('Notice Board App Comments List', Gallery3.Selected);
If(CountRows(Gallery3.AllItems) = 0, Patch('Notice Board App', {ID: Value(DataCardValue7.Text)}, {Has_Comments: false}));

 

When I tried it this morning, the first update to True worked and the Icon appeared.  When I deleted the last comment, the update to False didnt work and the Icon is still visible.

 

Yesterday I was seeing instances where the update to True sometimes didnt happen but the update to False would (after manually updating the field to True in my list).

Meneghino
Level 10

Re: UpdateIf issue

Why do you need a flag at all?  Can you not just set the icon's Visible property to

!IsEmpty(Gallery3.AllItems)

Apologies if I am not fully understanding your scenario, but having a flag seems redundant (i.e. not normalised)

fbxiii
Level: Powered On

Re: UpdateIf issue

It is to display an Icon on the initial browsing page.  If I add the !IsEmpty code, all Items have the icon visible as the user needs to click through to the next screen to populate Gallery 3.

 

The Icon currently has a Visible property of: If(Has_Comments = true,true,false) which is a field in the Datasource of the browse gallery.

 

The Patch/Updates I am trying to make are to that field.

 

BrowseGallery.PNG

fbxiii
Level: Powered On

Re: UpdateIf issue

I have got it working Smiley Happy

 

I changed the code on the Delete button to this:  

 

If(CountRows(Gallery3.AllItems) = 1, Patch('Notice Board App', {ID: Value(DataCardValue7.Text)}, {Has_Comments: false}));

Remove('Notice Board App Comments List', Gallery3.Selected);

Embarrisingly, I also discovered I had hard coded an ID value on the form so it was updating that record Smiley Frustrated