cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
fs92
Helper I
Helper I

PowerApps Component Framework howto init and update custom views

Hi,

 

currently I am implementing a custom list in a model driven app. I noticed that while filtering the data the init method as well as the updateView method is called, furthermore the updateView method is called 3 times. However, the new view is not rendered.

My guess is that the async promises are not correctly ordered and processed by my components, so that the init method at the end resets everything to or overwrites it with the original data.

What would be the right way to do this?
1. Initially render the components (by this I mean the render code in the init or updateView method)?
2. if the data is refreshed, how do the async calls have to be processed to render the view again?

Currently the code looks like the following:

 

  public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement) {
    this._context = context;
    //load the global context with the app properties.
    this._globalContext = Xrm.Utility.getGlobalContext();
    this._globalContext.getCurrentAppProperties().then((appProperties:any) =>{
      this._currentAppProperties = appProperties;
      this._projectList = React.createElement(ProjectDetailList,{context:this._context, appProperties: this._currentAppProperties, globalContext: this._globalContext});
      ReactDOM.render(React.createElement(Fabric, null, this._projectList), container);
    }, (error:any) =>{console.log(error)});
  }

  public updateView(context: ComponentFramework.Context<IInputs>): void {
    // storing the latest context from the control.
    this._context = context;
    this._globalContext = Xrm.Utility.getGlobalContext();
    this._globalContext.getCurrentAppProperties().then((appProperties:any) =>{
      this._currentAppProperties = appProperties;
      ReactDOM.render(React.createElement(Fabric, null, React.createElement(ProjectDetailList,{context:this._context, appProperties: this._currentAppProperties, globalContext: this._globalContext})), this._container);
    }, (error:any) =>{console.log(error)});
    console.log("NEW CONTEXT!!!! ->>>>>>>>>>>>>>>>>>>>>>>")
    console.log(this._currentAppProperties);
    console.log(context);
    console.log(this._context);
 
  }


Best regards.

 

1 ACCEPTED SOLUTION

Accepted Solutions
fs92
Helper I
Helper I

I have found the issue.

 

1. Don't run code which renders components in the Init Method!

2. run the render code in the UpdateView Method

3. Add a ComponentDidUpdate and ReceivedProps in the Component you want to render and call set.state() method with the received data.

Addiontaly add the paging size like described on this post: https://www.inogic.com/blog/2019/09/get-all-the-records-of-dataset-grid-control-swiftly/

Example Code:

 public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement) {

    this._notifyOutputChanged = notifyOutputChanged.bind(this);
    this._container = container;
    this._globalContext = Xrm.Utility.getGlobalContext();
    this._globalContext.getCurrentAppProperties().then((appProperties: any) => {
      this._currentAppProperties = appProperties;
    }, (error: any) => { console.log(error) });
  }


  /**
   * Called when any value in the property bag has changed. This includes field values, data-sets, global values such as container height and width, offline status, control metadata values such as label, visible, etc.
   * @param context The entire property bag available to control via Context Object; It contains values as set up by the customizer mapped to names defined in the manifest, as well as utility functions
   */
  public updateView(context: ComponentFramework.Context<IInputs>): void {
    if (!context.parameters.dataSetGrid.loading) {

      if (context.parameters.dataSetGrid.paging != null && context.parameters.dataSetGrid.paging.hasNextPage == true) {

        //set page size

        context.parameters.dataSetGrid.paging.setPageSize(5000);

        //load next paging

        context.parameters.dataSetGrid.paging.loadNextPage();

      } else {

        //load the global context with the app properties.
        this._context = context;

        this._projectListProps = {
          notifyChange: this.notifyChange,
          globalContext: this._globalContext,
          appProperties: this._currentAppProperties,
          context: context,
        }
        this._projectList = React.createElement(ProjectDetailList, this._projectListProps);
        ReactDOM.render(React.createElement(Fabric, null, this._projectList), this._container);

        console.log("NEW CONTEXT!!!! ->>>>>>>>>>>>>>>>>>>>>>>")
        console.log(this._currentAppProperties);
        console.log(context);
        console.log(this._context);

      }
    }else{
      //TODO: ADD RENDERING WITH SHIMMER!!
    }

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Bumping for visibility 

 

@Anonymous 

fs92
Helper I
Helper I

I have found the issue.

 

1. Don't run code which renders components in the Init Method!

2. run the render code in the UpdateView Method

3. Add a ComponentDidUpdate and ReceivedProps in the Component you want to render and call set.state() method with the received data.

Addiontaly add the paging size like described on this post: https://www.inogic.com/blog/2019/09/get-all-the-records-of-dataset-grid-control-swiftly/

Example Code:

 public init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLDivElement) {

    this._notifyOutputChanged = notifyOutputChanged.bind(this);
    this._container = container;
    this._globalContext = Xrm.Utility.getGlobalContext();
    this._globalContext.getCurrentAppProperties().then((appProperties: any) => {
      this._currentAppProperties = appProperties;
    }, (error: any) => { console.log(error) });
  }


  /**
   * Called when any value in the property bag has changed. This includes field values, data-sets, global values such as container height and width, offline status, control metadata values such as label, visible, etc.
   * @param context The entire property bag available to control via Context Object; It contains values as set up by the customizer mapped to names defined in the manifest, as well as utility functions
   */
  public updateView(context: ComponentFramework.Context<IInputs>): void {
    if (!context.parameters.dataSetGrid.loading) {

      if (context.parameters.dataSetGrid.paging != null && context.parameters.dataSetGrid.paging.hasNextPage == true) {

        //set page size

        context.parameters.dataSetGrid.paging.setPageSize(5000);

        //load next paging

        context.parameters.dataSetGrid.paging.loadNextPage();

      } else {

        //load the global context with the app properties.
        this._context = context;

        this._projectListProps = {
          notifyChange: this.notifyChange,
          globalContext: this._globalContext,
          appProperties: this._currentAppProperties,
          context: context,
        }
        this._projectList = React.createElement(ProjectDetailList, this._projectListProps);
        ReactDOM.render(React.createElement(Fabric, null, this._projectList), this._container);

        console.log("NEW CONTEXT!!!! ->>>>>>>>>>>>>>>>>>>>>>>")
        console.log(this._currentAppProperties);
        console.log(context);
        console.log(this._context);

      }
    }else{
      //TODO: ADD RENDERING WITH SHIMMER!!
    }

 

 

View solution in original post

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,457)