cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Codebug
Frequent Visitor

PCF - getOutput is not updating field in the form

I have a create virtual react-based pcf. It triggers from a change of a bound field and updates another output field. Currently, in the manifest, the properties look like the below,

 

<property name="Customer" display-name-key="Customer" description-key="Bind the customer field from which the address fields will be brought" of-type="Lookup.Customer" usage="bound" required="true" />

<property name="BoundTest" display-name-key="Bound Field" description-key="Bound Field" of-type="SingleLine.Text" usage="output" required="false" />

 

my part of my index.ts is below,

public updateView(context: ComponentFramework.Context<IInputs>): React.ReactElement {        
        const props : IAddressComponentProps = this.ConstructProps(context);
        return React.createElement(AddressComponent, props);
    }

    private ConstructProps = (context : ComponentFramework.Context<IInputs>) =>{
        const addressFieldMaps = this.ConstructAddressMapFromContext(context)
        const entityRepository = new EntityRepository(context.webAPI, addressFieldMaps)

        const parentEntity : DynamicsEntity = {
            entityLogicalName : (<any>context).parameters.Customer.raw[0].LogicalName,
            entityId : (<any>context).parameters.Customer.raw[0].Id._formattedGuid
            //entityId : '39269c3e-a55d-4eae-ae8d-3091818562d6'
        };

        const childEntity : DynamicsEntity = {
            entityLogicalName  : (<any>context).page.entityTypeName,
            entityId : (<any>context).page.entityId
        };

        return {
            parentEntity : parentEntity,
            childEntity : childEntity,            
            showButton : (context.parameters.ShowButton.raw === 'yes'),
            entityRepository : entityRepository,  
            doSomething : this.doSomething
        }
    }

public doSomething = (bdFiled : string) :void => {
        console.log(bdFiled)
        debugger;
        this._boundField = bdFiled;
        this.notifyOutputChanged();
    }
    /**
     * It is called by the framework prior to a control receiving new data.
     * @returns an object based on nomenclature defined in manifest, expecting object[s] for property marked as “bound” or “output”
     */
    public getOutputs(): IOutputs {        
        return {
            BoundTest : this._boundField
         };
    }

 

from the react view component i can call doSomething method and there is no error. however i cannot see the bound field getting updated.

bound field.png

i am not sure if the getOutput is supposed to update a field in the form in this way. this post hints that it might be possible or may be i am misunderstanding the usage. I have also read through @DianaBirkelbach 's blog post for the updateview lifecycle. not sure if this would be different for virtual PCFs?

1 ACCEPTED SOLUTION

Accepted Solutions
DianaBirkelbach
Most Valuable Professional
Most Valuable Professional

Hi @Codebug , 

 

I suggest to define the "BoundTest" Property as usage="bound" instead of "output". 

The output property is a special usage, mostly used on Canvas Apps and CustomPages. On Model-driven forms, you can get that value using getOutputs: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/control...

 

But since you want to change the value of a bound field, you just need to declare the property as bound.

 

Hope this helps!

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

View solution in original post

8 REPLIES 8
DianaBirkelbach
Most Valuable Professional
Most Valuable Professional

Hi @Codebug , 

 

I suggest to define the "BoundTest" Property as usage="bound" instead of "output". 

The output property is a special usage, mostly used on Canvas Apps and CustomPages. On Model-driven forms, you can get that value using getOutputs: https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/control...

 

But since you want to change the value of a bound field, you just need to declare the property as bound.

 

Hope this helps!

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."
Codebug
Frequent Visitor

hi @DianaBirkelbach ,

Thanks so much for your answer. I am checking now.

 

personally, i feel like the values for the target field should automatically change based on the event of the control. this will then mean i do not have to call 

formContext.getControl(arg).getOutputs();

periodically to check if the state of the field(s) have changed.

thanks again

Codebug
Frequent Visitor

Hi @DianaBirkelbach ,

i have given your solution a go and it works like a charm. I had to set the params which I want to be wired with the form fields as bound but not required. i then have to call the notifyOutputChanged function to call the setter function. 

 

 

public doSomething = (bdFiled : string) :void => {
        console.log(bdFiled)        
        this._boundField = bdFiled;
        this.notifyOutputChanged();
    }

public getOutputs(): IOutputs {        
        return {
            BoundTest : this._boundField
         };
    }

 

I learned that any parameter defined in the manifest file can be considered both IInputs and IOutputs type even if i do not explicitly mention the params output.

 

 

Hi @Codebug , hi @DianaBirkelbach 

 

Thank you very much for this thread. Your solutions brought me one step further.

 

In my case I have a component with a text field bound as input that is converted into a QR-Code and I would like to store the generated image into another output field.

 

 

 

If I define a  of-type "Object", I cannot find my component in Power apps. Do you have an idea on how to store a data object into a bound output Image field?

 

Thanks in advance

 

Roland

Codebug
Frequent Visitor

Hi @RolandM, i have not tried this exact use case but just thinking out loud,

if you have already converted the string into byte array,

 

Option 1

may be, convert the byte array to a base64 string and output it as a string to see if you can see your control. i am saying this because if you had used backend code then you'd have done it in this way. 

 

Option 2

Good old patch command should do the trick. (where you update the record with the new field value). although it is an extra call and is inefficient but it should work. 

 

again neither of the options are tried. give them a go. see if they solve the problem 

DianaBirkelbach
Most Valuable Professional
Most Valuable Professional

Hi @RolandM , 

If you are on a model-driven form, you could

- just like @Codebug  says, convert it to a string, and define the property of type string and usage "bound" where you return that value. That way the form will autosave the value with the other attributes on the form.
- if you would still like to work with object , then you can declare the property of usage "output" and use form-scripting to getOutputs. I have a blog about this (in that use case I'm using it for a dataset PCF, but it could work for you too): https://dianabirkelbach.wordpress.com/2023/05/19/let-your-subgrid-dataset-pcf-communicate-with-the-f...

 

For canvas apps, I have another blog about output objects: https://dianabirkelbach.wordpress.com/2022/11/13/call-fetchxml-inside-custom-pages-without-flows-the...

Or have a look to the PCF samples about output object: https://github.com/microsoft/PowerApps-Samples/tree/master/component-framework/ObjectOutputControl

 

Hope this helps!

Kind regards,
Diana
----------
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Thank you very much @Codebug and @DianaBirkelbach 

 

Actually I have the image converted to base 64 string. The problem is that I am not able to select the image column in the configuration of my pcf component. If I define "SingleLine.Text" in my manifest, I can only select text columns and there is no type "Image" available. Do you know a workaround for that?

 

 

@DianaBirkelbach by the way, I am using a model-driven form 

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,905)