Hi,
How can we refresh the PCF dataset control automatically when a record is added in the subgrid?
On create of a record (in a subgrid), we have a plugin to auto populate a field in the PCF. At the moment, the page has to be manually refresh to display the update.
I have tried the GridControl.addOnLoad() to refresh the subgrid of the PCF but the update is still not displaying.
Any suggestions?
Thanks!
Regards,
Marvs
HI @marvinbarnuevo ,
The console part in the gif is much too fast for me to read.
So have you logged the content of the dataset inside the updateView method of your PCF, and the data is not refreshed there?
Could you customize the subgrid for the records expected in the PCF using a standard subgrid, and check if the records are shown there? Do you get the records after making a form refresh?
In the NetworkProtocoll you should see the fetch that's sent, in order to populate the dataset for the PCF. Is the data shown there (in the response)? Or maybe is there a filter set in the fetch that's filtering it out?
Kind regards,
Diana
Hi @DianaBirkelbach,
Appreciate your response.
I am pretty sure it is not making another update on the same record.
Below is a .gif of what's happening when I added a record in the subgrid. You could see, at the later part of the .gif when I opened the developer tools, the console.log I added in the script (not yet in the PCF solution though).
Even after adding another record in the subgrid, the first update didn't appear.
Regards,
Marvin
Hi @marvinbarnuevo ,
I was sure I answered yesterday, but the answer seems to be lost somehow.
I have no idea if you got a notification. Let's see if I get it together again.
What we could still try:
- make sure that the plugin, which registered on Pre-Stagte, is changing the target (not making another update on the same record).
- try to make a console.log inside your updateView method of your your PCF. Log the data you get there. This could help to see if is a rendering issue (maybe react?) with the PCF
- try to see if the refresh is called to soon. Maybe insert the second record in the subgrid, and check if in the meanwhile the first record was added. Or try in the console Xrm.Page.getControl("PCF_RPL").refresh() a little later, to see if the change is reflected a little later.
Kind regards,
Diana
Hi @DianaBirkelbach,
Thanks for your response.
First, let me correct myself. I initially stated that we have a plugin that auto populates the field in the PCF. What we actually have is a custom workflow triggered on create of the record.
Below is our implementation. Almost exactly the as yours:
function addSubgridListener(formContext) {
let gridContext = formContext.getControl("subgrid_articulation_pathway");
let refreshPcf = function () {
formContext.getControl("PCF_RPL").refresh();
console.log("test PCF");
};
gridContext.addOnLoad(refreshPcf);
}
Then, I created a plugin that has similar logic to what we've built using custom workflow. Registered it on Pre Stage as you stated.
But still the update is not reflecting.
Hi @marvinbarnuevo ,
Since the event after adding the record in the subgrid is triggered, you need to refresh your dataset PCF.
I've just tried it out in the console: Xrm.Page.ui.controls.get("MyDatasetPCF").refresh(), and I get the data that I've changed in another window. So this should work too.
So you need to register something like this on your form OnLoad:
function myFunction(executionContext) {
var formContext = executionContext.getFormContext(); // get the form context
var gridContext = formContext.getControl("YourSubgrid");// get the grid context
var refreshPCF = function () {
formContext.ui.controls.get("YourDatasetPCFControlName").refresh();
};
gridContext.addOnLoad(refreshPCF);
}
You could make some console.log in your PCF "updateView" method, to check that is called.
If you did exactly the same and still doesn't work, maybe there is an issue with the PlugIn. It should be sync, and since you want to preset data, should be registered on "Pre" stage. Maybe the "refresh" is executed before the PlugIn is done?
Hope one of these helps.
Kind regards,
Diana
@ben-thompson- is there any possible workaround for this?
@ben-thompson- Below is the screenshot of the part of the PCF which doesn't display the updated value.
It is the latter. We are creating a record in a separate sub grid in which we wanted to display the other details of that record in the above screenshot.
Are you talking about the PCF control or the dataset contained within the PCF control. What is not being refreshed with the new record?
Also where is the new record being created in the PCF component or in a separate subgrid - if it's the latter there won't be anything triggering a refresh on the rest of the page.
@DianaBirkelbach- You got it absolutely correct.
The event is getting triggered (console log and alert is getting displayed once a record is added in the subgrid) and can see the PCF is loading - there's a loading icon showing up. But the issue is the PCF dataset control does not reflect the changes.
Hi @marvinbarnuevo ,
Let me check if I've got it right:
You have a standard subgrid control and an own PCF dataset control, both on a form, both on the same tab. When a record is added in the subgrid, you need to refresh your PCF dataset control.
Correct?
Do you have issues to get an event for that? Can you check if the event on the subgrid is triggered (like making a console.log)?
Or is it the issue that you don't get your PCF (dataset) refreshed?
Kind regards,
Diana
WarrenBelz
109
Most Valuable Professional
Michael E. Gernaey
82
Super User 2025 Season 1
MS.Ragavendar
72