Quantcast
Channel: SCN : Discussion List - SAP BusinessObjects Design Studio
Viewing all articles
Browse latest Browse all 4041

SDK: Building a MultiDim JSON for use in Script Contributions (ZTL)

$
0
0

This question is related to the SCN thread here: Coloring a Traffic Light based on a BEX exception

 

I'm posting a new question to step back and pursue a more general approach.

 

I've run into trouble building MultiDim JSON strings for BIAL methods like getConditionalFormatValueExt and setDataSelection. I seem to have all the correct working parts, but I get an exception when trying to execute my BIAL script in Design Studio:

 

Error during script processing: "DENDOGRAM_1.setTrafficLightValueArray();" "com.sap.ip.bi.zen.rt.framework.jsengine.JsEngineException: org.mozilla.javascript.WrappedException: Wrapped java.lang.ArrayIndexOutOfBoundsException: 1 (setTrafficLightValueArray#18)

  at com.sap.ip.bi.zen.rt.framework.jsengine.rhino.RhinoJsEngine.handleError(RhinoJsEngine.java:139)

  at com.sap.ip.bi.zen.rt.framework.jsengine.rhino.RhinoJsEngine.doRunScript(RhinoJsEngine.java:70)

 

Caused by: java.lang.ArrayIndexOutOfBoundsException: 1

  at com.sap.ip.bi.zen.rt.components.ds.impl.DataSourceCommandResolver.getMapFromString(DataSourceCommandResolver.java:108)

  at com.sap.ip.bi.zen.rt.components.ds.impl.DataSourceCommandResolver.getConditionalFormatValueExt(DataSourceCommandResolver.java:1016)

 

Based on a conversation yesterday, I took Mike Howles' suggestion to use a getter and see the results of my ZTL in Design Studio. I'm doing something like this:

 

  1. component.js identifies the Key Figure/Measure to use for the conditional formatting based on input from UI and stores it in property this.kfExceptionKey
  2. ZTL function this.getExceptionKF() correctly returns string: 00733D6SQ53WODKEN1C53S73O
  3. component.js uses a members.forEach function to iterate through all visible members and store their JSON stringified MultiDim in an array called this.conditionalFormatMultiDim
  4. ZTL function this.getConditionalFormatMultiDim() returns a concatenated string due to no array types being available in ZTL functions:

    {"SBOP2_D05":"ALL_CARS","0UNIT":"ST","0CURRENCY":"EUR"},{"SBOP2_D05":"KIDS_CARS","0UNIT":"ST","0CURRENCY":"EUR"},{"SBOP2_D05":"TEEN_CARS","0UNIT":"ST","0CURRENCY":"EUR"},{"SBOP2_D05":"SENIOR_CARS","0UNIT":"ST","0CURRENCY":"EUR"},{"SBOP2_D05":"FAMILY_CARS","0UNIT":"ST","0CURRENCY":"EUR"}

  5. ZTL function this.setTrafficLightValueArray() reads the string (no longer an array) from this.getConditionalFormatMultiDim() and splits it into a new array based on a regular expression. Then, I discard the array values containing only the seperator comma and create a new array:

var condFormatStringCollection = this.getConditionalFormatMultiDim();  var conditionalFormatArray = [];  var conditionalFormatArrayFinal = [];  conditionalFormatArray = condFormatStringCollection.split(/([,])(?=[{])/);  for(var i=0;i<conditionalFormatArray.length;i++) {  var tmpResult = conditionalFormatArray[i];  if (tmpResult !== ",") {  conditionalFormatArrayFinal.push(tmpResult);  }  }  var condFormatValueArray = [];  this.finalCondForm = conditionalFormatArrayFinal[1];

   6. ZTL function this.getFinalCondForm() returns the value at index 1:

 

 

          {"SBOP2_D05":"KIDS_CARS","0UNIT":"ST","0CURRENCY":"EUR"}


I tried constructing a bunch of BIAL manually in Design Studio to troubleshoot:


  • DS_3.getConditionalFormatValueExt(DENDOGRAM_1.getExceptionKF(), DENDOGRAM_1.getFinalCondForm()); returns java.lang.ArrayIndexOutOfBoundsException: 1

  • DS_3.getConditionalFormatValueExt("00733D6SQ53WODKEN1C53S73O", {

       "SBOP2_D05": "KIDS_CARS",

       "0UNIT": "PC",

       "0CURRENCY": "EUR"

 

     });
        Works properly and returns a value of 7.

 

  • DS_3.getConditionalFormatValueExt(DENDOGRAM_1.getExceptionKF(), {"SBOP2_D05":"KIDS_CARS","0UNIT":"ST","0CURRENCY":"EUR"});

        Works properly and returns a value of 7. Note, I just copied the exact string that was returned by DENDOGRAM_1.getFinalCondForm()                     and it works! The only problem is when the ZTL function returns a string into the getConditionalFormatValueExt.


The source is available on GitHub if you want to take a look:


DesignStudio/com.sap.sample.procop at master · jmsrpp/DesignStudio · GitHub

 

I'd greatly appreciate any insights.

 

Thanks,

Jim


Viewing all articles
Browse latest Browse all 4041

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>