
Announcements
I'm developing a PCF for OptionSet attributes in a model driven app for Dynamics 365. We're using this PCF multiple times on the same form.
For some attributes the PCF is not getting any value in context.parameters.OptionSet.raw. This happens only sometimes though. I've tested this using the same record: one time I open it and it may work as expected, but the next time there might just be no value being passed. I created logging in the init and updateView functions and I'm just getting undefined in those cases.
The desired value is definitely set in the record (I've verified this by getting the record via CDS). I disabled all the Form scripts, there are no business rules, and there are no onChange scripts.
Has someone here run into this?
tldr;
Don't call notifyOutputChanged from updateView.
You know those times when you're stuck on a problem for hours, then you ask someone else, and shortly after that you solve it yourself?
I disabled all UI generation in my PCF so there's only logging happening. Turns out that sometimes the logs looked like this:
and sometimes like this:
In my PCF the magic happens in a function that takes in the value as a number, does its UI magic, and at the end calls notifyOutputChanged. This function was called when the user used the UI as intended (registered on UI events), but also when updateView was being called. So when it's called the first time with no value it reports this exact missing value back to the model driven app, making it think that there's no value supposed to be set in the first place, and after that the PCF won't recieve the correct value anymore. Not calling notifyOutputChanged from updateView but only when the user initiated this function solved my issue.
Now as to why the PCF would sometimes get called with no value in the first place is beyond me.