cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Custom Widget - Use of NavigationUtils in Code (from standard Type Library)

mfrieser
Participant
0 Kudos
567

Hello everyone,

I am developing a custom widget for the SAC and want to use the Analytics Designer API (https://help.sap.com/doc/958d4c11261f42e992e8d01a4c0dde25/release/en-US/index.html).

In my case I want to be able to change the viewed story from the inside of my custom widget code. So I defined a function that looks like this:

class Widget extends HTMLElement {

changeStory(storyId,pageId){

NavigationUtils.openStory(storyId,pageId);

}

...

}

The problem that I face is that the call of the "changeStory"-function throws following error: Uncaught ReferenceError: NavigationUtils is not defined.

Now my question is how I could access the NavigationUtils Component from the inside of my code (https://help.sap.com/doc/958d4c11261f42e992e8d01a4c0dde25/release/en-US/index.html#NavigationUtils).

Thanks and best regards

Michael

View Entire Topic
vishalakshmi
Contributor
0 Kudos

Hello Michael,

You may need to reference the API script in your HTML file or import it using a module system if you are using one.

// Import the Analytics Designer API (Example, actual path may vary)

import { NavigationUtils } from '@sap/analyticsdesigner';

SAC widgets often require proper initialization. Ensure that your widget is initialized correctly and that the Analytics Designer API is available at the time your widget is created.

class Widget extends HTMLElement {

constructor() {

super();

// Initialize your widget and the Analytics Designer API

// Ensure proper initialization steps are taken here

}

changeStory(storyId, pageId) {

// Use NavigationUtils.openStory here

NavigationUtils.openStory(storyId, pageId);

}

// Other widget code...

}

If you're encountering issues with undefined components, it might be due to the timing of when your widget code is executed. Make sure that you're accessing the NavigationUtils component after the necessary dependencies have loaded.

Ensure that your custom widget is compatible with the version of SAC you are using and that the API you are trying to access is available in that version.

Thanks,

Lakskhmi.