Through this blog you will learn how to dynamically pass filters from an SAC analytic application to a page in a story and filter the widgets in the story page thereupon.
When you are working in SAP Analytics Cloud Analytics Application, you might have a requirement to dynamically pass a dimension value from an analytic application to a story.
For eg. Suppose you have a pie chart in the Analytic Application with measure as “Number of Workorders” and dimension as “WorkOrder type” which has values [PM,PT,CM,ST] and the user expects that on clicking on any value of “WorkOrder Type” i.e. PM/PT/CM in the Pie chart, the table in the story which contains the details about the Workorders be filtered by the Workorder type selected in the chart.
This is achievable in analytics application using scripting.
In order to achieve this, we need to use the Navigation Script API which allows you to navigate from an opened analytic application to any page of a story.
The script API takes the id of the story and the page in the story to which you want to jump to from the analytic application and opens the page in a new tab if the parameter “newTab” is set to true.
Below is the syntax of the openStory API.
NavigationUtils.openStory( storyID: string, pageID: string, parameters?: UrlParameter | UrlParameter, newTab?: boolean)
Now the question is how to get the values of the above arguments:
1. Story ID
Open the below URL in your browser window and search for your story name in the output .
Replace <TENANT> with the public SAP Analytics Cloud URL for your tenant
In the output search for the story ID which would look like the below highlighted ID and replace the storyID part in the openStory API with it.
2. Page ID:
In order to get the ID of the page that you intend to jump on after clicking on the hyperlink in your story ,open the below URL where n is the page number that you want to jump on from the analytic application.
Say you want to jump on page 2 then replace n with 2.
Once you open the above URL by replacing the Tenant and page number , the page number value n that you have entered will be replaced with its ID in the URL.
Note down the ID and replace the pageID part in the openStory API with it.
3.URL Parameters: Parameters to apply filters to a story can be added to the open story URL.
3.i. Dimension ID (Required Parameter)
f<XX> Dim = <Dimension ID>
Here <XX> is any number between 01 and 99.If you want to pass filters for multiple dimensions then assign a new value to XX each time you add a new dimension.
<Dimension ID> is the technical ID of the dimension.
eg. f01Dim = “0CUSTOMER”
f02Dim = “0MATERIAL”
How to find a dimension ID:
- Open a story in SAP Analytics Cloud and add a story filter .This will bring up a list of all the available dimensions. Hover the cursor over the dimension name ,the tooltip then shows the dimension ID and description as they are available in the model.
3.ii. Model ID (Required Parameter)
Parameter Syntax: f<XX>Model=<MODEL_ID>
Here <XX> is any number between 01 and 99.If you want to pass filters for multiple models assign a unique value to XX each time you add a new dimension.
f01Model = “XYZ”
f02Model = “ABC”
Note: After index 01, the model parameter can be omitted as long as the model for that filter is the same as the model used by the previously indexed filter.
To find the model ID look for the description of the model in the output that you have received while searching for your story and get the corresponding model ID which would look like below:
3.iii. Dimension Values(Required Parameter)
These are the filter values that you want to pass to the dimension id.
To find dimension filter values:
Open a story in SAP Analytics cloud and add a story filter. You will get a list of dimensions available in the model. Select the dimension that you want to pass filters to .Once the dimension is added, click on it to get a list of dimension values which can be displayed in ID and description format.
Note down the IDs and pass them in your openStory API like this:
f01Val = “100000” —in case of single member filter
f01Val = [“100000″,”100001”]
3.iv. Include/Exclude(Optional Parameter, by default the value is set to in)
Here <XX> is any number between 01 and 99. If there are several filters passed for filtering then assign a unique value of <XX> to each filter.
Here ‘in’ indicates the filter values should be included in the member selection for filtering the widget .’notIn’ indicates the filter values should be excluded in the member selection for filtering the widget.
Set the value of this parameter to true if you want to open the story page in a new tab else set it to false.
After passing all the above parameters my script code looks like:
NavigationUtils.openStory("C9181xxxxxxxxxxxxxxxxxxxxxx,"523xxxxx-xxx-xxxx-xxxx-xxxxxxxxxxxx", [UrlParameter.create("f01Model","x.y:zzzzzzzzzzzzzzzzzzzzzzzzzz"), //Model ID UrlParameter.create("f01Dim","ZWRKTY0"), //Dimension UrlParameter.create("f01Val","PM"), //Dimension value UrlParameter.create("f01Op","in")],true); //Include/Exclude followed by newTab
Now when we run the analytic application and select the dimension value in your chart, based on which you want to filter the story which in my case is the work order type ,my story page is opened in a new tab and Workorder type is added in the Story Filter with value equal to the selected value in the analytic application.
If you think this blog post has helped you in any way please like and comment in the comment section below. Also if you have any queries I would be happy to answer them.