cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
a33ik
Level 8

Different behavior of the control depending on the type of the form - Create/Update

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?

1 ACCEPTED SOLUTION

Accepted Solutions
ScottDurow
Level 8

Re: Different behavior of the control depending on the type of the form - Create/Update

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.

View solution in original post

5 REPLIES 5
DanzMaverick
Level: Powered On

Re: Different behavior of the control depending on the type of the form - Create/Update

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.

a33ik
Level 8

Re: Different behavior of the control depending on the type of the form - Create/Update

@DanzMaverick 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.

ScottDurow
Level 8

Re: Different behavior of the control depending on the type of the form - Create/Update

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.

View solution in original post

ScottDurow
Level 8

Re: Different behavior of the control depending on the type of the form - Create/Update


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

See https://powerusers.microsoft.com/t5/PowerApps-Component-Framework/Access-Page-Context-within-a-compo...

a33ik
Level 8

Re: Different behavior of the control depending on the type of the form - Create/Update

@ScottDurow , thanks! That's what I needed.

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (5,508)