Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Answered

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

(0) ShareShare
ReportReport
Posted on by 3,304 Most Valuable Professional

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?

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Different behavior of the control depending on the type of the form - Create/Update

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

  • ScottDurow Profile Picture
    1,039 on at
    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-component/m-p/362492/highlight/true#M879

  • Verified answer
    ScottDurow Profile Picture
    1,039 on at
    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.

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Different behavior of the control depending on the type of the form - Create/Update

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

  • Danish N. Profile Picture
    186 on at
    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.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Power Apps Pro Dev & ISV

#1
WarrenBelz Profile Picture

WarrenBelz 109 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 82 Super User 2025 Season 1

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 72

Overall leaderboard