Select to view content in your preferred language

Change widget configuration at runtime for a custom Experience Builder widget

224
1
09-11-2024 11:42 PM
Labels (1)
shoaibmomincontractlandstaffco
New Contributor

I have implemented the AppConfigProcessorExtension to update my widget configuration at runtime. Following is a snippet of the code that I am using. The updates I am trying to apply using setIn method are not being reflected when I output the newAppConfig in the console log for my current widget. 

What is the correct way to update widget configuration using this extension point?

async process (appConfig: AppConfig) : Promise<AppConfig> {
   
    // Do not replace when run in builder.
    if (window.jimuConfig.isInBuilder) {
      return Promise.resolve(appConfig);
    }

    // Clone the current app config to make it immutable
    let newAppConfig = Immutable(appConfig);

    // Find the widget in the app configuration
    const widgetConfig = newAppConfig.widgets[this.widgetId];

    //doing stuff to set searchwidgetconfiguration and usedatasources
    ///
   
    if (widgetConfig) {
      const updatedWidgetConfig = widgetConfig
        .setIn(['config', 'datasourceConfig'], this.searchWidgetConfig)
        .setIn(['useDataSources'], this.useDataSources);
      console.log(updatedWidgetConfig, "updatedWidgetConfig");
      newAppConfig = newAppConfig.setIn(['widgets', this.widgetId], updatedWidgetConfig);
    }
   
    return Promise.resolve(newAppConfig.asMutable({ deep: true }));

  }

 

1 Reply
Junshan_Liu
Frequent Contributor

The appConfig in the process() function is mutable, so you can just update it directly, like this widgetConfig.abc=123.

0 Kudos