Forum Discussion

Nojustice's avatar
Nojustice
Advocate I
5 years ago

getSlicerState on Inactive Pages

Hello All,

 

We are currently trying to implement functionality where we save the state of all slicers on a report so that when a user comes back to the report in the future, it re-renders in the state that the user left the report in.

 

We are however experiencing an issues whereby getSlicerState seems to error if retrieving slicerstates from any other page other than the active one. 

See example below:-

const pages = await report.getPages();
for (const page of pages) {
   let theSlicers;
   let allOfTheVisuals;
   await page
        .getVisuals()
        .then((visuals) => {
          allOfTheVisuals = visuals;
        })
        .catch((err) => {
          console.log(`error getting the page visuals:`, err);
        });
   // Separate out the slicers from the visuals
   theSlicers = allOfTheVisuals.filter((visual) => {
          return visual.type == "slicer";
        });
   const slicerFilterData = [];
      for (const slicer of theSlicers) {
        await slicer
          .getSlicerState()
          .then((filters) => {
            // If there are no filters then don't add the slicer.
            if (filters === undefined || filters.length === 0) return;

            const obj: VisualLevelFilter = {
              name: slicer.name,
              type: slicer.type,
              filters: filters,
            };
            slicerFilterData.push(obj); //Does not populate this when slicers are not on active page
          })
          .catch(
            (err) => {
              throw(err); //Errors here
            } 
          );
      }
}

Has anyone encountered this problem before, or does anyone have a workaround for this?

 

Much Appreciated

 

Graham

5 Replies

Replies have been turned off for this discussion
  • Sorry I forgot to add the error 

     

     {"message":"visualConfigIsNotInitialized","detailedMessage":"Visual container config is not initialized"}
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Nojustice,

      According to your error message, it seems like your request did not include the configs so that it failed to initialize.

      If that is the case, I'd like to suggest you take a look following links about power bi javascript and correspond configurations.

      Configure report settings 

      Embed Configuration Details 
      Regards,

      Xiaoxin Sheng

      • Nojustice's avatar
        Nojustice
        Advocate I

        Anonymous 

        I have only provided an example piece of code, at the point this is executed the report is already rendered on the screen so all the configuration has already been passed to it.

         

        As an example the report contains 2 tabs, 

        Tab1 = Books

        Tab2 = Authors

         

        The user alters some slicers on Books, then moves to Authors and alters some slicers.

        The user hits save (code in my original post is executed)

        It seems to only getslicerstate from the slicers on the current page (in this case Authors), I want to store what the slicerstate is from Books page.

         

        Hope this brings some more clarity

  • Anonymous's avatar
    Anonymous
    Not applicable

    Nojustice I have just come across the same issue. Have you found a workaround or been able to solve this?