Pass list name to org chart for rendering

I’ve got a requirement to create versions of the org chart monthly and archive the older versions. These older versions will need to be able to be rendered easily without manually configuring a new web part.

To make an archive version, I was going to save the current structure from the UPS to a SharePoint list. What I’d like to do is present a list of org chart version to the user, and make the org chart display the chart based on which list (org chart version) is selected.

Is there a way I can pass the list name to the org chart config to use?

Hello @cbenson,

Thank you for your question.

I afraid there is no way to change the data source for a chart automatically without setting it up in the Configuration Wizard.

I would suggest to add one more webpart with a list as the data source and just choose there a list that you would like to show at a particulat moment. It will prevent losing settings for the user profiles data source.

In the screenshot below I have shown how to pick up a custom list for using it as the data source in Org Chart:

Also please remember to specify the fields mapping for the lists:

Please, feel free to ask any further questions.

Best Regards,
Anna Dorokhova
Plumsail Team

Yes, what I was hoping to do was be able to dynamically change the SharePoint list in the config as I’ll have several list versions available, but with different names. This solution requires me to manually change the list name in the config.

Hello @cbenson,

There is actually a solution that could meet your business needs.

You may create somewhere a list of links to an archive org chart page. This org chart should use a list as the data source. The links will have a get parameter with a list ID in it, they will look something like https://yourdomain.sharepoint.com/SitePages/archiveOrgChart.aspx?archivelist=03159E61-4CF5-4CEA-A995-D957D4C58243
It will work as a navigation for the users.

Then you can pass this get parameter to the org chart config inside of prerenderAction method like this:

renderer.prerenderAction = function(completed){
  try {   
      var archivelist = window.location.href.split('archivelist=')[1];  
      console.log(archivelist);
          if (archivelist !== undefined){
            renderer.config.ListDataSourceSettings.ListId = archivelist;
          }   
  }
  catch(err) {
     } 
  finally {
    completed();
  }
}

You will need to specify this code in the Custom JavaScript step of the Configuration Wizard.

You may find more information on the prerender method here.

Best Regards,
Anna Dorokhova
Plumsail Team

1 Like

Thanks Anna, I’ll give this a try and let you know how it goes!

1 Like

That seems to have worked! Though I need to clear the cache before the new list shows. Is there also a way to force the chart to clear the cache on load?

Hello @cbenson,

I am glad it was helpful!

Please, uncheck the "Enable caching" checkbox in the General Settngs step of the Configuration Wizard. It will disable caching.

Best Regards,
Anna Dorokhova
Plumsail Team

@cbenson,

You may also use dataProvider.clearCache(); method to clear cache only on load.

Great!! Thank you! :slight_smile:

1 Like

Anna,
Where would I add this data to force a clear cache on load?

Hello @turtlgal,

You may add it on loading started event like this:

renderer.onLoadingStarted(
  function(){
    renderer.dataProvider.clearCache();
  }
);

Best regard,
Anna Dorokhova
Plumsail Team