cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

SAP Analytics Cloud: How can I compare variable values?

yj
Participant
0 Likes
548

Hello all,

in SAC I use BW live connection within a story. To read the value of a variable 0S_CUS I use:

var cust = Chart_59.getDataSource().getVariableValues("0S_CUS")[0];

 Then I try to compare the value of variable "cust". Why: I would like to hide some pages in my SAC story if the customer number is greater than 10000000. The infoobject for variable 0S_CUS is 0CUSTOMER (data type: CHAR, length 10).

But this is not working:

var border = "0010000000";
if (cust > border) {
Application.setPageVisible("Page_7", false);
} else {
Application.setPageVisible("Page_7", true);
}

The variable 0S_CUS is a select-option but we pre-fill it with only one value. 

The error is: auto-type conversion isn't supported.

Thanks for your help!

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor
0 Likes

@yj 

You can try the below to get the value of variable.

var cust = Chart_59.getDataSource().getVariableValues("0S_CUS")[0];

if (cust.type==VariableValueType.Single)

{
var singleValue = cast(Type.SingleVariableValue, value);
var cust_val=singleValue.value;
}

 

cust_val could be directly an integer and if not you can convert to integer as below.

cust_num=ConvertUtils.stringToNumber(cust_val);

 

Hope this helps !

Nikhil

yj
Participant
0 Likes

Hi Nikhil,

The following script works for me:

var cust = Chart_59.getDataSource().getVariableValues("0S_CUS")[0];
var cust_single = cast(Type.SingleVariableValue, cust);
var cust_val = cust_single.value;
var cust_num = ConvertUtils.stringToNumber(cust_val);

var border = 10000000;

if (cust_num > border) {
Application.setPageVisible("Page_7", false);
} else {
Application.setPageVisible("Page_7", true);
}

Thanks for your help!

Regards,
Yvonne

N1kh1l
Active Contributor
0 Likes
Yj, I am glad it worked. Kindly close the thread by accepting the answer for larger community.

Answers (1)

Answers (1)

N1kh1l
Active Contributor
0 Likes

   Yj,

var border = "0010000000";  This variable is of type string and you are trying to do an integer operation  > on it which would not work.

Please convert both both cust and border explicitly to number/integer and then try the comparison. You can use the below

ConvertUtils.stringToNumber(stringVariable)

border_num=ConvertUtils.stringToNumber(border); 

cust_num=ConvertUtils.stringToNumber(cust);

if (cust_num > border_num) {
Application.setPageVisible("Page_7", false);
} else {
Application.setPageVisible("Page_7", true);
}

Hope this helps !

Nikhil

 

 

 

 

 

 

 

yj
Participant
0 Likes

Hi Nikhil,

Thank you. I try the following:

var cust = Chart_59.getDataSource().getVariableValues("0S_CUS")[0];
var cust_num = ConvertUtils.stringToNumber(cust);

But for the conversion from STRING to NUMBER, I get the error message: Invalid argument at index 1: Cannot convert from "VariableValue" to "string"

Regards,
Yvonne