Can we execute a java script (formcontext.data.refresh) from with in a pcf sub-grid control or from outside.
I have a scenario where I have 2 PCF Subgrids when a record is added to one I want to update the other pcf subgrid
PCF controls do not have direct access to the client script libraries, but you can still accomplish your objective, just indirectly.
PCF #1 is a dataset control, but you can still bind it to fields as output values. Pick a field on your form (or make a new one for the purpose) that PCF #1 can write a value to in order to announce success. Then set that same field as the bound input for PCF #2 (that is, make PCF 2 a Field type control, not a dataset control) When the field gets updated, PCF2's updateView will get called, and you will know to fire a RetrieveMultiple to update your 'grid'
Hi @RishiBhutani ,
My first thought was to try some form scripting, use some grid events to attach to selection on the first and refresh the second dataset using the sdk for the GridControl. Unfortunately I didn't had the time to try it out (I guess the problem is to detect if a record was added).
Second thought would be to use standard JS (window.postMessage) like in my older blog (https://dianabirkelbach.wordpress.com/2020/05/15/can-pcfs-communicate/) but this requires that both PCFs are self made and I'm not so sure if it's supported (I consider it a gray zone). The idea would be that the first PCF knows about adding the record, sends a message, and the secons PCF listens to the message and triggers a refresh its the own dataset.
@cchannon : the idea with an output parameter is interesting. According to the docs, the parameters are only of usage input or bound: https://docs.microsoft.com/en-us/powerapps/developer/component-framework/manifest-schema-reference/p... I've seen the output parameters only on CanvasApps. Have you tried out the output parameter in model-driven apps?
In case the output parameters are working, then I would go with your idea regarding the PCF#1, but I wouldn't change the second PCF to a field type PCF (since we loose quite a few functionality provided by the framework). Instead I would use form scripting, register it to "onChange" of the output parameter of the PCF#1, and use form scripting to refresh the second PCF (formcontext.data.refresh as @RishiBhutani mentioned) .
Hope this helps!
Kind regards,
Diana
TBH @DianaBirkelbach, you've got me there, and I will be doing some testing on my own to check. It is entirely possible I have never actually used a non-bound output param other than in the context of a canvas app. I will let you know what I find.
Also, I completely agree with your tweak at the end there. Using a formscript event to refresh the grid is an objectively better way to trigger the dataset PCF as opposed to rewriting it as a field PCF. Nice call!