cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Bhuvita
Helper II
Helper II

setSelectedRecordIds method triggering update view everytime

I having checkbox on my PCF control on click of which we are using setSelectedRecordIds to set the id of selected record to show ribbon buttons. But somehow from past one week when this method is triggered it calls the update view method which refreshes my control. 

 

In the screenshot we can see in updated properties selecteditems.

 

Anybody facing same issue ?

 

1 ACCEPTED SOLUTION

Accepted Solutions
aroudaki
Microsoft
Microsoft

when setting selected records updateView should be called since it is changing the dataset state. 
However, setting selected records wasn't causing updateView before which was incorrect.
This issue been recently fixed. That's why you see the change in the behavior. 

Based on documentation for updateView, this method will be called for any data or metadata changes and the controls should assume updateView will be called multiple times during lifecycle of the control. Best practice is to use updatedProperties and other methods on dataset to decide if the control need to react (re-render) on a call to updateView or not.

View solution in original post

5 REPLIES 5
sheldoncopper73
Resolver I
Resolver I

We are facing the same issue in our project.

On click of an element, we select the record using setSelectedRecordIds but this method triggers the updateView method and resulting in the reset of the selection of records. We also notice that this issue is occurring in some CRM regions like crm4. On CRM8 and CRM region it is working as expected.

Some of our clients have raised this issue to us.


@AnqiChen @HemantG could you please help us out?

Thanks in advance.

DianaBirkelbach
Super User
Super User

Hi @Bhuvita , Hi @sheldoncopper73 , 

 

I can see that the updateView is called after setSelectedRecordIds, but I cannot say if that is new.

In the context.updatedProperties I see ["SelectedItems"], and the dataset.getSelectedRecordIds() still has the selection.

Does getSelectedRecordIds return [] to you, when updateView is called.

 

My dataset PCF still works, but since the updateView is called often, I use React.memo around my React component and render only if the dataset or container width or height changes. I'm not sure if I'm lucky on my environment (crm4 region), or the React.memo does the job for me.

 

Hope it helps!

 

Kind regards,

Diana

 

 

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
KAL
Frequent Visitor

@Bhuvita @sheldoncopper73 

 

As a workaround you can try setting a private property to flag that update view should not run when you are setting selected record IDs.

aroudaki
Microsoft
Microsoft

when setting selected records updateView should be called since it is changing the dataset state. 
However, setting selected records wasn't causing updateView before which was incorrect.
This issue been recently fixed. That's why you see the change in the behavior. 

Based on documentation for updateView, this method will be called for any data or metadata changes and the controls should assume updateView will be called multiple times during lifecycle of the control. Best practice is to use updatedProperties and other methods on dataset to decide if the control need to react (re-render) on a call to updateView or not.

Bhuvita
Helper II
Helper II

Hi @DianaBirkelbach 

getselectedrecordid do return data indeed when update view is called.

So I think what  @aroudaki @KAL suggested of using a flag on updated properties to decide whether controls needs to react or not on call of update view should work.

 

Thanks everyone for the reply.

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (2,337)