cancel
Showing results for 
Search instead for 
Did you mean: 

Pass value from Variable to Dropdown -> convert "unknown type" to "string"

paumcl
Explorer
0 Kudos
710

Hello Together,

I must admit I am struggling with the way SAC handles fetching data and passing it forward.

I have this working coding which is getting the selected value from a dropdown (IPC_Month) and passing it on to a global function:

var monthdetail = IPC_Month.getInputControlDataSource().getActiveSelectedMembers();
var monthdetail2 = monthdetail[0].displayId;
GS_Functions.setCalMonth_KPI(monthdetail2);

Now I want to do the same with a variable X_CALMONTH_05. But now it tells me, that displayID is an unused property.

var month = Chart_KPI_Sales_KF.getDataSource().getVariableValues("X_CALMONTH_05");
var month2 = month[0].displayID
IPC_Month.getInputControlDataSource().setSelectedMembers(month2);

As I need to slice the month variable, I tried it this way, but now the system complains, that it cannot convert from unknown type to string (g_yyyymm is a script variable in string).

var month = Chart_KPI_Sales_KF.getDataSource().getVariableValues("X_CALMONTH_05");
var MM = month.slice(0,2);
var YYYY = month.slice (3,8);
G_YYYYMM = YYYY+MM;
IPC_Month.getInputControlDataSource().setSelectedMembers(G_YYYYMM);

So now I am stuck and thankful for your help.

BR Clemens

Accepted Solutions (1)

Accepted Solutions (1)

N1kh1l
Active Contributor
0 Kudos

paumcl

Try the below, I think the returned value needs casting

var month = Chart_KPI_Sales_KF.getDataSource().getVariableValues("X_CALMONTH_05")[0];
switch (month.type){
case VariableValueType.Single:
var month2 = cast(Type.SingleVariableValue, month);
console.log(month2.value);
break;}
var G_YYYYMM=month2.value;
console.log(G_YYYYMM);// just to check the paased month
IPC_Month.getInputControlDataSource().setSelectedMembers(G_YYYYMM);

Or If the variable is always single value return type.

var month = Chart_KPI_Sales_KF.getDataSource().getVariableValues("X_CALMONTH_05")[0];
var month2 = cast(Type.SingleVariableValue, month);
console.log(month2.value); 
var G_YYYYMM=month2.value;
IPC_Month.getInputControlDataSource().setSelectedMembers(G_YYYYMM);

Br.Nikhil

Answers (7)

Answers (7)

paumcl
Explorer
0 Kudos

That did it, thanks a lot. Comming from Lumira Designer, it is still some way to go for me to understand this coding.

BR Clemens

N1kh1l
Active Contributor
0 Kudos

paumcl

paumclI have a variable called MONTH equivalent to your X_CALMONTH_05. See below I am getting proper output

var month =Table_1.getDataSource().getVariableValues("MONTH")[0];
console.log(month);
var month2 = cast(Type.SingleVariableValue, month);
var G_YYYYMM=month2.value;
console.log("G_YYYYMM Passed"); 
console.log(G_YYYYMM);

Output:

Just check if you are missing something in your code

Br.

Nikhil

paumcl
Explorer
0 Kudos

Sorry to say, but month.type is an unused property.

N1kh1l
Active Contributor
0 Kudos

paumcl

Something is miss as type is a property being returned

The Log gives me back the following: {"value": "202309", "type": "Single"}

Its difficult as I do not see the exact logs and error

paumcl
Explorer
0 Kudos

G_YYYYMM would already be a global variabel with type string.

But on yyyymm=month.value I get the message, that "value" is an unused property. And furthermore Type mismatch: cannot convert from Unknown type to string.

And if I try it with a locale variable like var yyyymm=month.value; the message changes to Type mismatch: cannot convert from Unknown type to Unknown type. The message with "value" is an unused property stays the same.

N1kh1l
Active Contributor
0 Kudos

paumcl

paumclJust use the below

var month = Chart_KPI_Sales_KF.getDataSource().getVariableValues("X_CALMONTH_05");
var G_YYYYMM=month.value;
console.log(G_YYYYMM);// just to check the paased month
IPC_Month.getInputControlDataSource().setSelectedMembers(G_YYYYMM);

Br.

Nikhil

paumcl
Explorer
0 Kudos

Hello Nikhil,

thanks for your answer.

The Log gives me back the following: {"value": "202309", "type": "Single"}

And seeing this, I am not even sure I need the slicing at all. But how would I get the type Single to a String?

BR Clemens

N1kh1l
Active Contributor
0 Kudos

paumcl

You should console.log the variables to see the output and determine the type. So the below will help you

console.log(month);

console.log(month2);

getVariableValues returns the values of the variable. Each value can be a single, multiple, or range variable value. The return type is definitely not string so you cannot directly use the returned value. I am assuming its a single variable value. so you should assign the value of the returned param into month2.

month2=month.value;// This can be clear once you post the output of the console.log variables.
month2=month[0].value; // or this if returns an array
 

You should be splicing month2 rather month right ?

Br.

Nikhil