{"id":786,"date":"2021-02-15T11:10:08","date_gmt":"2021-02-15T10:10:08","guid":{"rendered":"https:\/\/ad-astra.com.pl\/?p=786"},"modified":"2021-02-15T11:10:10","modified_gmt":"2021-02-15T10:10:10","slug":"analytics-designer-przyklady-uzycia-konsoli-i-getresultset","status":"publish","type":"post","link":"https:\/\/ad-astra.com.pl\/en\/2021\/02\/15\/analytics-designer-przyklady-uzycia-konsoli-i-getresultset\/","title":{"rendered":"Using Console and getResultSet in Analytic Designer"},"content":{"rendered":"<p>SAP Analytics Cloud is an extensive cloud platform that provides many necessary tools in the field of Business Intelligence. An example of such a tool is Analytic Designer - a module that allows you to create advanced analytical applications that can be enriched with scripts written in a simplified version of JavaScript.<\/p>\n\n\n\n<p>In this article, we will introduce <strong>getResultSet<\/strong>\u2013 an example of an interesting built-in script function. It returns all data cells in a given object \u2013it\u2019s like an \"explorer\" that browses through each element of a table and lists information about it.<\/p>\n\n\n\n<p>There are many possible use cases for this function - we can read specific rows, columns, copy and paste cell values to other items. In this article we will try to briefly present such examples and possible uses of the function.<\/p>\n\n\n\n<p>We will operate on a simple example - a small employee absence table, broken down over the years.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"605\" height=\"236\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image.png\" alt=\"\" class=\"wp-image-789\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image.png 605w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-300x117.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-535x209.png 535w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-16x6.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-513x200.png 513w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-512x200.png 512w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/figure>\n\n\n\n<p>Using the menu at the top of the interface, insert a button and position it above the table (<strong>Insert &gt; Button<\/strong>)<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"328\" height=\"185\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-1.png\" alt=\"\" class=\"wp-image-791\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-1.png 328w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-1-300x169.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-1-16x9.png 16w\" sizes=\"(max-width: 328px) 100vw, 328px\" \/><\/figure>\n\n\n\n<p>Using the <strong>Styling<\/strong> pane on the right side of the interface, we can rename it (in our case, \"Odczytaj\")<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"350\" height=\"248\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-2.png\" alt=\"\" class=\"wp-image-792\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-2.png 350w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-2-300x213.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-2-16x12.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-2-282x200.png 282w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/figure>\n\n\n\n<p>Analytic Designer executes scripts using <strong>Events<\/strong>. For example, to run a script by pressing a button, we need to put it in the button's <strong>onClick<\/strong> event. To do this, <strong>select the button<\/strong>in the application, and then click on the&nbsp; <strong>icon with three dots<\/strong> , <strong>Edit Scripts&nbsp; i onClick.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"417\" height=\"138\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-3.png\" alt=\"\" class=\"wp-image-793\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-3.png 417w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-3-300x99.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-3-16x5.png 16w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/figure>\n\n\n\n<p>Using <strong>getResultSet<\/strong> , we want to read the data from the employee absence table and save it to a variable in JavaScript. To do this, enter the following code into the script editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var elementy_tabeli = Table_1.getDataSource().getResultSet();<\/code><\/pre>\n\n\n\n<p>Where :<\/p>\n\n\n\n<p><strong>Var<\/strong> - variable initialization<\/p>\n\n\n\n<p><strong>Elementy_tabeli<\/strong> \u2013 the name of the variable in which we want to store the data<\/p>\n\n\n\n<p><strong>Table_1.getDataDataSource()<\/strong> \u2013 data source retrieved from the table<\/p>\n\n\n\n<p>At this point, after pressing the button, the data from the table will be loaded into the variable. Now we will try to display that data in the console. As <strong>Elementy_tabeli <\/strong>is an Array type variable, to read its values, we need to use a <strong>For Loop<\/strong> <strong><\/strong>(as presented below):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (var i = 0; i &lt; elementy_tabeli.length; i++)\n\t{\n\t\tconsole.log(elementy_tabeli&#91;i]);\n\t}  \n<\/code><\/pre>\n\n\n\n<p>The entire script should look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"403\" height=\"89\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-4.png\" alt=\"\" class=\"wp-image-795\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-4.png 403w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-4-300x66.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-4-16x4.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-4-400x89.png 400w\" sizes=\"(max-width: 403px) 100vw, 403px\" \/><\/figure>\n\n\n\n<p><strong>Console<\/strong>.<strong>log()<\/strong> allows you to display specified items in the browser console.<\/p>\n\n\n\n<p>Save the changes and run the application. Open the console with the F12 button (in the example we use Google Chrome) and then press the buton we added. The result should look like below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"934\" height=\"417\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6.png\" alt=\"\" class=\"wp-image-798\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6.png 934w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6-300x134.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6-768x343.png 768w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6-535x239.png 535w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6-16x7.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-6-448x200.png 448w\" sizes=\"(max-width: 934px) 100vw, 934px\" \/><\/figure>\n\n\n\n<p>Note that each retrieved item can be expanded to see its information in more detail. By examining the elements, we can see that <strong>getResultSet traverses the table from left to right, top to bottom.<\/strong><\/p>\n\n\n\n<p>We can also count the number of elements in the table, script example below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var elementy_tabeli = Table_1.getDataSource().getResultSet();\nvar ilosc_elementow = 0;\nfor (var i = 0; i &lt; elementy_tabeli.length; i++)\n\t{\n\t\tconsole.log(elementy_tabeli&#91;i]);\n\t\tilosc_elementow++;\n\t}\nconsole.log(\"Ilo\u015b\u0107 element\u00f3w to : \" +ilosc_elementow.toString());\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"237\" height=\"82\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-7.png\" alt=\"\" class=\"wp-image-799\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-7.png 237w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-7-16x6.png 16w\" sizes=\"(max-width: 237px) 100vw, 237px\" \/><\/figure>\n\n\n\n<p>Please note : We get the value of 23 even though the table consists of 24 cells becase getResultSet <strong>only returns objects that have values.<\/strong><\/p>\n\n\n\n<p>Now we will try to \"extract\" and <strong>display the value of the last element in the table in a text object<\/strong>. In our example, we changed the data source:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"605\" height=\"264\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8.png\" alt=\"\" class=\"wp-image-800\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8.png 605w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8-300x131.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8-535x233.png 535w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8-16x7.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-8-458x200.png 458w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/figure>\n\n\n\n<p>We insert a Text object (<strong>Insert &gt; Text<\/strong>) to the application and place it next to the button.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"605\" height=\"120\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-9.png\" alt=\"\" class=\"wp-image-801\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-9.png 605w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-9-300x60.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-9-535x106.png 535w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-9-16x3.png 16w\" sizes=\"(max-width: 605px) 100vw, 605px\" \/><\/figure>\n\n\n\n<p>To <strong>save the last element<\/strong> from the table to a variable, to the previous script add the following entry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var ostatni_element = elementy_tabeli&#91;elementy_tabeli.length-1];<\/code><\/pre>\n\n\n\n<p>(we insert [table length - 1]  as the element number because it is indexed from 0)<\/p>\n\n\n\n<p>To be able to use the values collected by GetResultSet, we must first<strong> understand how they are stored<\/strong>. For example, let's take a look at the last entry of our script in the console:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"499\" height=\"213\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-10.png\" alt=\"\" class=\"wp-image-802\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-10.png 499w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-10-300x128.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-10-16x7.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-10-469x200.png 469w\" sizes=\"(max-width: 499px) 100vw, 499px\" \/><\/figure>\n\n\n\n<p>We can see that a single entry consists of 3 elements that constitute the technical names of the objects used in the table -<\/p>\n\n\n\n<p>&#8211; @MeasureDimension (<strong>measure<\/strong>)<\/p>\n\n\n\n<p>&#8211; Date_703i1904sd (<strong>date<\/strong>)<\/p>\n\n\n\n<p>&#8211; Location_4nm2e04531 (<strong>location<\/strong>).<\/p>\n\n\n\n<p>From a technical point of view, a single entry is nothing more than a small table. We can see that the cell value (<strong>18.66<\/strong>) is stored in <strong>@MeasureDimension<\/strong> element for property called <strong>formattedValue<\/strong>. Let's use this knowledge in the script.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var wartosc_ostatniego_elementu = ostatni_element&#91;\"@MeasureDimension\"].formattedValue;<\/code><\/pre>\n\n\n\n<p>As the table index we give the value @MeasureDimension, and after the dot, we choose the property that interests us (formattedValue).<\/p>\n\n\n\n<p>We enter this value  into the text element:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Text_1.applyText(wartosc_ostatniego_elementu);<\/code><\/pre>\n\n\n\n<p>The entire code should look like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var elementy_tabeli = Table_1.getDataSource().getResultSet();\nfor (var i = 0; i &lt; elementy_tabeli.length; i++)\n\t{\n\t\tconsole.log(elementy_tabeli&#91;i]);\n\t}\nvar ostatni_element = elementy_tabeli&#91;elementy_tabeli.length-1];\nvar wartosc_ostatniego_elementu = ostatni_element&#91;\"@MeasureDimension\"].formattedValue;\nText_1.applyText(wartosc_ostatniego_elementu);\n<\/code><\/pre>\n\n\n\n<p>We save and run the application. Pressing the button should return a similar result as below:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"731\" height=\"307\" src=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12.png\" alt=\"\" class=\"wp-image-805\" srcset=\"https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12.png 731w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12-300x126.png 300w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12-535x225.png 535w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12-16x7.png 16w, https:\/\/ad-astra.com.pl\/wp-content\/uploads\/2021\/02\/image-12-476x200.png 476w\" sizes=\"(max-width: 731px) 100vw, 731px\" \/><\/figure>\n\n\n\n<p>This concludes our article on using GetResultSet in applications. For more information on GetResultSet and other useful Analytic Designer features, please refer to the official documentation -<\/p>\n\n\n\n<p><a href=\"https:\/\/help.sap.com\/doc\/958d4c11261f42e992e8d01a4c0dde25\/2020.21\/en-US\/index.html\">https:\/\/help.sap.com\/doc\/958d4c11261f42e992e8d01a4c0dde25\/2020.21\/en-US\/index.html<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>SAP Analytics Cloud is an extensive cloud platform that provides many necessary tools in the field of Business Intelligence. An example of such a tool is Analytic Designer - a module that allows you to create advanced analytical applications that can be enriched with scripts written in a simplified version of JavaScript.\n\nIn this article, we will introduce getResultSet....<\/p>","protected":false},"author":2,"featured_media":798,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[61,59,58,62],"_links":{"self":[{"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/posts\/786"}],"collection":[{"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/comments?post=786"}],"version-history":[{"count":9,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/posts\/786\/revisions"}],"predecessor-version":[{"id":809,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/posts\/786\/revisions\/809"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/media\/798"}],"wp:attachment":[{"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/media?parent=786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/categories?post=786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ad-astra.com.pl\/en\/wp-json\/wp\/v2\/tags?post=786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}