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);
@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