cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Reading properties via script

09-22-2020 9:12 AM
brian_bailey2 Explorer
9912 views 11 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

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 Likes

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 Member
0 Likes

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 Likes

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 Likes

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 Member
0 Likes

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 Likes

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

Answers (1)

Answers (1)

former_member186338
Active Contributor
0 Likes

You can do the following:

Add your model as a planning model to script:

Then for some button add the code:

            var member=PlanningModel_1.getMember("Account","PL010");
            var prop=member.properties;
            console.log(prop);

In this sample I am using Account dimension with the member PL010

Result you can see in F12 Console:

Account dimension has 2 properties: accType and TARGETACC

brian_bailey2
Explorer
0 Likes

Hi Vadim, thanks for your help

I have tried your suggestion, I can't make it work, unfortunately, I have never used planning

Thank you anyway

Brian

former_member186338
Active Contributor
0 Likes

brian.bailey2

Unfortunately, using ResultMemberProperties API you can only get properties shown in the report table...

The code:

var prop=Table_1.getDataSource().getResultMember("Account",selection1).properties;
console.log(prop);

Will show property value only if you can see it in the report table:

Result:

The only way to get any property (not any, but most) for some member is to use PlanningModel

Create some simple planning model and test yourself

P.S. Don't ask me what is the proper name of the developer of the API like this

kvsreekar38
Participant
0 Likes

vadim.kalinin

Do you know an API to get a Version dimension member based on a Property Flag value ?

In the below example, based on the Property 'Current Forecast Version' flag 'X' value I would like to read the version value public.F04