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

Refresh grid content pcf

I have designed a custom grid control for one of the requirement with subgrid display. I am creating a new record from the control using xrm. Webapi.createrecord.however, the sub grid content is not getting refreshed after record creation.

Update view method of pcf is not called. I have tried to call grid control. Refresh() and notify outputchanged but of no avail. Appreciate help here. 

9 REPLIES 9
Solution Sage
Solution Sage

Why do you want to refresh the view (that's an additional API call for zero real benefit)?

 

Unless plugins are running in the background your PCF component already has all the data you need to add the record into the dataset and refresh the grid control yourself

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

Thanks Ben.

 

How do I add records to dataset from js. I see dataset. Records does not have and add property. Can you please help?

 

On the other hand, how do I refresh view without refreshing the page. I tried context.data.refresh(false) but did not work

Super User
Super User

Hi @Goutham , 

I think  @ben-thompson  is right, but I am not aware of a way to add records in the dataset. So that would mean that you need to build another (PCF internal) model for your data, which has to be updated each time updateView is called (if your dataset was changed). I think in the end it depends how often you need to add records, and decide if you need to refresh your dataset or make an internal model on top.

To refresh the dataset from inside your PCF, you need to call:

context.parameters.dataset.refresh()

where "dataset" is the name of your "<data-set" property in the manifest.

Here is the reference: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/reference/dataset/refresh

There is no parameter for refresh.

Hope this helps!

 

Kind regards,

Diana

Diana is right - you can't update the Dataset itself - but you can refresh it (it's an additional api call though, so I would use that approach within a D365 world (10,000+ api calls a day) and not in a power app world (2,000 calls a day).

 

In the last few dataset PCF's I've created the data ends up in a more flexible JSON object - so we can manipulate it appropriately (say to consolidate figures or perform calculations).

---
If this post has answered your question please consider it for "Accept as Solution" or if it has been helpful give it a "Thumbs Up".

Thank You Ben and Diana!! and yes, I have already tried this context.dataset.referesh() but did not work. I also tried Xrm.page.data.refersh(), calling notifyourputchanged() and having an input variable in pcf, then updating it in success call back of create record(so that update view will be triggered) but none of them refreshed the custom grid dataset.  OOB grids are getting refreshed(Async) when i call Xrm.page.data.refersh().

 

However, when i refresh entire page, I am able to see the updates in custom grid.(this is not what i want)

Super User
Super User

Hi @Goutham , 

Given the tests that you mentioned, I'd like to specify a few things. Maybe we get closer to something that we overlooked.

 

- How do you create the record? Since you are inside a PCF, you should create it using the feature "webApi" that you declare in the manifest 

<feature-usage>
    <uses-feature name="WebAPI" required="true" />
</feature-usage>

After that you get in your "context" a "webAPI".

Using Xrm.* inside a PCF is not supported.

 

- calling notityOutputChanges will have no effect for a dataset PCF. That's because there are no output parameters allowed.

 

- It is not possible to mix a field-PCF with a dataset-PCF. In a dataset PCF you can have also properties, but only of type "input" (not of type "bound"). That means that the control won't be refreshed when the input parameter changes.

 

So my next test would be:

Being inside the PCF code, after the creation of the record, wait for the promise, and then call

context.parameters.<yourDatasetName>.refresh()

and check the console if you get an error. Check the network protocol, to see the corresponding request and the response. Is the new record listed there? 

If I've got it wrong, if you've actually meant to call a refresh from outside the PCF (from scripting), we need to work another way. Just let me know.

 

Kind regards,

Diana

Helper I
Helper I

Thank you for detailed analysis Diane!! yes i did Try dataset.refresh()  inside success callback of webapi.create but the content inside dataset did not update. I even tried to call dataset.refersh() and also xrm.page.data.refersh()(as supported for now but may discontinue in future) inside  window.timeout at regular intervals(Say 5000 ms) after record creation as a test, but did not work too.

 

No sure if i am missing any concept(which may be minor one). for now, only way i see to refresh the dataset is to refresh the form.

Microsoft
Microsoft

Hi Goutham,

 

Can you provide more details on the repro? I have tried Diana's suggestion and am able to create records, refresh the dataset, and the updateView is called again with the new record. Can you share the code snippet(s) of what you've tried (and whether you observed any differences with the different things you've tried)?

 

Have you tried looking at the network tab in the browser's F12 tools to check if either the create or refresh network calls are not going out?

Helper I
Helper I

Thank you everyone for your reply!! The issue is with React framework not rerendering and calling dataset.referesh() and  force rendering the reactDOM fixed the issue,

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Users online (74,746)