Hi community - here is my dilemma:
I have a PCF control bound to a contact lookup field on a MDA form.
I need to perform some action if the lookup field has no value (null) on form load.
In updateView, I am getting the field value with
context.parameters.MyLookupField.raw
Now, if I open a form where that lookup field has a value in the database, context.parameters.ContactLookup.formatted returns null for the first two times that updateView is called, then on the third time, it returns the actual value. Similarly, if I use context.parameters.MyLookupField.raw, I get an empty array two times, then a value on the third time.
To illustrate, I logged the field value at the top of init and updateView like this:
init () {
console.log('init', context.parameters.ContactLookup.formatted)
...
}
updateView () {
console.log('update', context.parameters.ContactLookup.formatted)
...
}
and this is what my console output looks like after the form loads:
init > null
update > null
update > null
update > 'John Doe'
So the behaviour I am seeing is that my action is sometimes being performed even though the field does have a value because the form has not fully loaded yet.
Does anybody know how to check if the form is fully loaded from within the PCF control in a supported way? (i.e. not using Xrm global object or the DOM).
The only two (not great) options I could come up with were:
- Check via WebApi if the field has a value
- Bind to some other field like FormLoaded and set that field value when the form loads to notify my PCF control
I don't like either of these options... I feel there should be a more elegant way to do this.
I would especially like to hear if @DianaBirkelbach has any ideas 🙂
Thanks!