I work on field-type control and based on the scenario it has to behave differently depending on the type of form:
For the create form scenario control has to be disabled. For the update form scenario it has to be enabled. Here is the code that works:
if (context.page.entityId == null) { //Code for create } else { //Code for update }
Here is the problem - when I create a record and save it control is not re-rendered so "Create" scenario control is shown. Is there any trick I'm not aware of to make it work?
@OOlashyn @DynamicsNinja you did attachments-viewer controls. How did you solve that scenario?
@ScottDurow , thanks! That's what I needed.
if (context.page.entityId == null) { //Code for create } else { //Code for update }
It's also worth nothing that apparently the way to get the entityId is using:
context.mode.contextInfo.entityId
Hey @a33ik
Some of my controls do a similar thing - but rather than being disabled they have to do some operations after the record has been saved (like creating related records etc.)
I get updateView called with entityId in the list of context.updatedProperties when the the record is saved.
Other interesting things you can get from this is when the user switches tabs or resizes the windw - you get an updateView called with layout in the context.updatedProperties.
@PowerMaverick thanks for your prompt reply! I use field (and property to which field is bound) as a placeholder and I don't touch the field in my code at all. The whole implementation of my control is similar to following one - https://github.com/DynamicsNinja/PCF-Carousel-Control/blob/master/CarouselControl/index.ts it just works with "Connection" records using WebApi.
Because I'm not touching the field and field is not changed via platform - updateView and init are not called.
I got the idea to investigate. Field that is changed during create and it's possible to bind to is createdon. On the "Create" form value will be null. For the "Update" it will be changed so that should trigger re-rendering.
For the control to get re-render updateView should get invoked. That happens when any of the bounded propery changes or notifyOutputChanged is invoked.
Not sure how you have your property bound but if the value of the attribute that is bound changes on save then the control will render or alternatively you can invoke notifyOutputChanged as stated earlier and make sure the output value is getting changed.
Hope that helps.
WarrenBelz
109
Most Valuable Professional
Michael E. Gernaey
82
Super User 2025 Season 1
MS.Ragavendar
72