cancel
Showing results for 
Search instead for 
Did you mean: 

SAC Script: empty/undefined input parameter of filterValues.type break the storry to an error

Martin_4
Participant
0 Kudos
442

Hi,

Problem:
-in a SAC script I want to grasp the value(s) of the Input Parameters of a BW query,
-some input parameters are not set, "undefined", "NULL",
-any command on filterValues.type  like "switch(filterValues.type){]" breaks the storry to an error,
-
in this sample where  the first empty variable is ZMO_VAR_REGIO01:

Martin_4_0-1722070791675.png

Design:
-query MANAGREP with 10 + Input Parameters
-SAC Story with table MANAGREP
-onResultChanged Event
-the code like bellow, the error raising section boxed in with //+++++++

Possible solution:
-identify empty filterValuetypes and sort them out
-How ?

Any advice is wellcome  :)!

ThanXs.
=====================================================================
Here is the full code, boxed in, //+++++++++++, the errornous section:
=====================================================================

// Get alle the variables form the Query
// MANAGREP is the Table / Query
var filterName = MANAGREP.getDataSource().getVariables();
console.log("++filterName:");
console.log( filterName);
 
//---------------------------------------------------------------------------------------------------------
// LOOP over all Input Parameter
for ( var j=0; j < filterName.length; j++){
   console.log("++filterName[j].id:");
   console.log( filterName[j].id);
 
   var filterValues = MANAGREP.getDataSource().getVariableValues(filterName[j].id)[0];
   console.log("++filterValues:");
   console.log(filterValues);
 
//---------------------------------------------------------------------------------------------------------
//Differentiate type of Input Parameter ( in ABABP: LT_RANGE) to treat values accordingly
    console.log("++filterValues.type:");
 
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Any operation on filterValues.type breaks with this error, if the parameter is empty, what means not set in the
// query:
// "
// Cannot read properties of undefined (reading 'type') 
// TypeError: Cannot read properties of undefined (reading 'type')
// at Proxy.eval (MANAGREP.onResultChanged.js:12:34)
//
// ----> How to handle an undefined input parameter ? <----------
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
    console.log(filterValues.type);
switch(filterValues.type){
 
case VariableValueType.Single:
         console.log("++VariableValueType.Single:");
         console.log(VariableValueType.Single);
 
// Get  a single value from the input parameter
     var singlefilterValue = cast(Type.SingleVariableValue, filterValues );
         console.log(" singlefilterValuefilterValues:");
         console.log( singlefilterValue.value);
//       Add some logic on the single values of the single inut parameter here:
         break;
 
   case VariableValueType.Multiple:
        console.log("++VariableValueType.Multiple:");
        console.log(VariableValueType.Multiple);
 
    var multiFilterValues = cast(Type.MultipleVariableValue,  filterValues);
        console.log("multiFilterValues filterValues:");
        console.log( multiFilterValues.values);
//---------------------------------------------------
// Loop over the values of the multiple value input parameter
    for ( var i = 0; i < multiFilterValues.values.length; i++){
      console.log("multiFilterValues.values[i]  filterValues:");
    console.log( multiFilterValues.values[i]);
//          Add some logic on the multiple values of the parameterhere:
    }
//---------------------------------------------------
// Loop END over the values of the parameter
     break;
case VariableValueType.Range:
     console.log("++VariableValueType.Range:");
         console.log(VariableValueType.Range);
//       Get the value of the ranges, how  ?
//       Add some logic on the range values of the range input parameter here:
         break;
 
   default:
console.log("++DEFAULT");
        break; 
//---------------------------------------------------------------------------------------------------------
//Differentiate type of Input Parameter ( in ABABP: LT_RANGE)
}
//---------------------------------------------------------------------------------------------------------
// LOOP over Input Parameter
}
console.log("FINISHED");
View Entire Topic
jonas_neurath
Explorer
0 Kudos

Hi Martin,

you can try by using an if/else statement. With the condition

if (yourvariable === undefined) 

to just continue with the filled values.

Hope this answer can help you and fixes your problem.

Best, Jonas