cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Reading properties via script

brian_bailey2
Explorer
0 Kudos
4,108

Hello everyone, I am very new to SAP Analytical Cloud and need some assistance

I have a public dimension based on customers, to this, I have added the description and several properties address, phone number etc

I have then created a model that contains this dimension along with other dimensions

I wish to use the model in an Analytical Application, this I have also done applying filters etc, what I am unable to do is read the properties via a script of the customer dimension so that I can display them in a text box, it does not sound that difficult to achieve any suggestions appreciated

Thank you

Brian

View Entire Topic
former_member664886
Discoverer

Hi Brian,

do you want to know what properties are available (like does the customer has an attribute address?) or do you want to know the value of the property (like what is the address of the customer?)

Best regards

Viet

brian_bailey2
Explorer
0 Kudos

Hello Viet, I can see the customer as an address property. I actually want to know the value so that I can have a popup that shows the full address of the customer, I have applied the description of the customer to the popup

Thanks for helping

Brian

former_member664886
Discoverer
0 Kudos

I usually implement a hidden chart into my Analytic Application and add the respective dimension. The following example script gets the description for a dimension value (dimension name is MENU_KEY). Use the developer tools of Chrome to see what console.log() prints out. In the script editor of SAC, I often use CTRL+SPACE for code completion if I don't know what kind of arguments a method expects. And the API Reference is also a good place to search for answers: https://help.sap.com/doc/958d4c11261f42e992e8d01a4c0dde25/release/en-US/index.html

For starters, this blog is also good: https://www.sapanalytics.cloud/introduction-to-scripting-in-analytics-designer/

N1kh1l
Active Contributor
0 Kudos

Hello,

Could not try this out but ResultMemberProperties API could be of help. Having issues with my tenant logon else could have tried and posted the results.

Nikhil

brian_bailey2
Explorer
0 Kudos

Hi Viet, thanks for your help it does return what I require

I do have 2 more questions however

Firstly in your example, you use selection[5], I have tried but I can't work out how to replace the 5 with a variable of the desired customer?

I currently have

var custsel = InputField_1.getValue();

console.log(Chart_5.getDataSource().getResultMember("Customer.PostalCode",{"Customer":selection[5].Customer}).description);

This gets the required customer number but I need the position in the array

Also, and I have not really looked at this yet, but when I use getDataSelections() it only returns 500 entries to the array?

Thanks

Brian

former_member664886
Discoverer
0 Kudos

Hi Brian,

glad that I could be of help.

In order to find the right entry, I often loop through the array with a for-loop. Something like the following might work for you (I assume that custsel contains the customer you search for). Since I have used only low-volume datasets so far I was not aware that getDataSelections() might have a limit. In such cases, I assume that we need to filter the data source of our dummy chart first before we use getDataSelection().

for (var i = 0; i < selection.length; i++) {
	if (selection[i].Customer === custsel) { 
			console.log(Chart_5.getDataSource().getResultMember("Customer.PostalCode",{"Customer":selection[i].Customer}).description);
	}
}
brian_bailey2
Explorer
0 Kudos

Hi Viet, thanks for your help, I was almost there, I had the loop but was trying to fill the array on initialisation.

I have now put the hidden table with the customer filter applied

Keep well and thanks again

Brian