Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Daniel_Davis
Product and Topic Expert
Product and Topic Expert
1,704

The Journey

I've been using SAP Analytics Cloud for almost 8 years and like many of you, have stuck to stories rather than Analytic Applications as I don't have a massive coding background. Well if truth be told, I'm old and so my Basic and Pascal skills haven't had an airing for quite a few years.

With the latest innovations such as the Optimised Design Experience and the ability to add script elements to existing stories, I have now started to 'enhance' my visual storytelling. It struck me that rather than go big bang I would take an existing SAC Story and add code where I could get some quick wins without having to write big chunks of code. Links to Part One and Part Two of my series are included to make life easy for those of you who've not yet read them.

So for this instalment we have to thank a customer who recently asked me "how do I reset a story to its initial state using scripting?". That got me thinking because there is no script method to 'reset' a story to its initial state. There is no application.reset(); method so one will need to think a little outside the box.

Below is my take on a reset button that when pushed will reset the whole story to its initial state and if you've seen my blogs before you'll know I try to keep code to a minimum.

Let's start by creating an optimised story in SAC such as the one illustrated below. It's pretty simple with 1 chart and 3 filters but yours can be as complicated as you choose - it won't affect the outcome.

Initial Story.jpg

We are actually going to be use bookmarks to achieve the reset, but we need to do some prep before we can add the code. Once you story is complete, we'll need to set some preferences within the story itself. Start by selecting the Story Settings > View Time Settings > Bookmarks option as shown below:

Set Bookmark Options.jpg

This is where you define what objects within a story are saved when you add a bookmark to a specific story. For this to work we will need all objects, filters, charts etc to be saved with the bookmark so that when we apply it everything is returned to the initial state of the story. The dialog box opens, and you need to check the All Components in the Story option.

Bookmark Options.jpg

Save, close and again Save your story. We now have a completed story and next we need to save a bookmark for the initial state. For this we simply View or Present the story and from the toolbar add a bookmark (Bookmark Current State) with the following settings selected.

Save.jpg

You must make sure you select all three checkboxes, give it a name and click Save. Once this is done you can apply that very same bookmark using the same menuitem to open the Initial State bookmark.

Apply.jpg

Now the clever part because once you apply that bookmark the browser URL will change and look something like the following:

https://SAP_Tenant/sap/fpa/ui/tenants/c40d8/app.html#/story2&/s2/25D3E6803716B26B8EA76751785064F0/?b...22305278-9717-4296-8809-298841349359&mode=view

Final step is to copy the part of the URL that's shown above in Blue and Bold and keep it safe for the final step. Close the story view tab and edit the original story. You need to add a button and button script to make this button reset the story when pushed. I like to remove the button text, add a tooltip and add an icon to the button before adding the script... something like this...

Top.jpg

and this...

Bottom.jpg

All that remains is to add some script to that button and you done - you know me by now - it's one line of code. You will notice that the bookmark argument is the same text we saved above from the URL and this is what the apply() function expects.

 

// Click the button to apply the bookmark saved in the previous step

Bookmarks.apply('22305278-9717-4296-8809-298841349359');

 

We're all done, you can now save the story and use as you wish. You can play with the filters, edit them, drill the chart but then push the button and the story will be reset to its initial state. #simples.

output.gif

5 Comments