Skip to content

Instantly share code, notes, and snippets.

@andrew-grischenko
Last active July 27, 2023 15:15
Show Gist options
  • Save andrew-grischenko/bce9896ee736d4db699fea336bf10a11 to your computer and use it in GitHub Desktop.
Save andrew-grischenko/bce9896ee736d4db699fea336bf10a11 to your computer and use it in GitHub Desktop.
Power Apps PCF - Reset component
...
export class SomeComponent implements ComponentFramework.StandardControl<IInputs, IOutputs> {
private has_been_reset: boolean;
...
public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container:HTMLDivElement)
{
this.has_been_reset = false;
...
}
...
public updateView(context: ComponentFramework.Context<IInputs>): void
{
if(context.parameters.Reset.raw && !this.has_been_reset){
this.has_been_reset = true;
// do the clean up logic here
...
} else
// Technically, this will be done on ANY change of a property, which we don't care about as long as
// it's also done on setting of the Reset property
this.has_been_reset = false;
...
}
...
<?xml version="1.0" encoding="utf-8" ?>
<manifest>
<control ...>
<property name="Reset" display-name-key="Reset" description-key="Reset from start" of-type="TwoOptions" usage="input" required="false" default-value="false"/>
...
</control>
</manifest>
// Declare in a code (on screen visible or something like that) a dummy reset variable
Set(DummyResetVariable, false);
// Bind your control's Reset property to a dummy reset variable
// In the Component's inspector set value of the property Reset to
DummyResetVariable
// Now when you need to reset a control, set the dummy variable
Set(DummyResetVariable, true);
Set(DummyResetVariable, false);
@SPB21
Copy link

SPB21 commented Sep 16, 2020

Hi Andrew, i've followed your approach to implement the reset functionality but when i import my PCF into the canvas app the 'Reset' property isnt available to set. Have you any idea why this would be?
Thanks

@andrew-grischenko
Copy link
Author

andrew-grischenko commented Sep 17, 2020

Hi SPB21,
Could you clarify please "isn't available to set" - so is it not displayed in the inspector and not available to read either or just read-only?
Also, as another suggestion, would you try another name, not Reset but Reset2? I haven't checked for a while, but wondering if MS introduced "Reset" property into the basic component model? Just a guess.

@SPB21
Copy link

SPB21 commented Sep 17, 2020

Andrew, i've updated the property name to be:
<property name="resetControl" display-name-key="resetControl" description-key="Reset from start" of-type="TwoOptions" usage="input" required="false" default-value="false"/> .

When i go to the Power App and look at my control properties i can see 'resetControl':
image

But when i try to set the property via a button OnSelect, it isnt available and i get the following error:
image

@andrew-grischenko
Copy link
Author

Ok, two things
In the sample screen, why do you try to set the value of another variable from the value of the controls property? It’s declared as input, not output.
Would you try
Set( editRequestAddress.resetControl, true); Set( editRequestAddress.resetControl, false);
?

Otherwise if you do need to read the control value try set usage=“bound” as mentioned here https://docs.microsoft.com/en-us/powerapps/developer/component-framework/manifest-schema-reference/property

@SPB21
Copy link

SPB21 commented Sep 17, 2020

Andrew, my apologies, i added the wrong image. this is what i should have added:
image

Where we are using Set( editRequestAddress.resetControl, true);

@andrew-grischenko
Copy link
Author

I see now. Sorry, it will not work and my bad publishing incorrect information. We can't set the property directly like that in PowerApps, we can set variables only. So, I've updated the gist as below, please let me know if it makes sense and works eventually for you.

// Declare in a code (on screen visible or something like that) a dummy reset variable
Set(DummyResetVariable, false);

// Bind your control's Reset property to a dummy reset variable
// In the Component's inspector set value of the property Reset to 

DummyResetVariable

// Now when you need to reset a control, set the dummy variable 

Set(DummyResetVariable, true);
Set(DummyResetVariable, false);

@SPB21
Copy link

SPB21 commented Sep 21, 2020

Thanks Andrew, this is the approach i took in the end. All working now. Thanks for your assistance.

@andrew-grischenko
Copy link
Author

Good to hear, thank you!

@mitchellromanuik
Copy link

mitchellromanuik commented Jul 27, 2023

Hi Andrew,

default-value in manifest doesn't appear to load false when using the pcf watch

^^ updated. default-value is only support by model-driven and not canvasApp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment