Facility Control

 View Only
  • 1.  Array to Parameter

    Posted 12-28-2018 19:26

    I'm having some trouble pushing an array to a string array parameter.

    Here is a quick example of what I'm trying to do.

    Upon executing the code, nothing gets written to the parameter and no errors pop up in the debug console.

    What am I missing here?

    <abs contexttype="opengear" id="_top" style="">
       <meta>
          <params>
             <param access="1" maxlength="0" name="List" oid="List" precision="0" stateless="true" type="STRING_ARRAY" widget="default">
                <value>0</value>
             </param>
          </params>
       </meta>
       <button buttontype="push" height="95" left="112" top="111" width="397">
          <task tasktype="ogscript">var testArr = ["Apples", "Oranges", "Bananas"]; 
       var cArray = []; 
       var x = testArr.length; 
       for (var i = 0; i < x; i++)
       {  
          cArray.push({"key":i,"value":testArr[i]});
       }
       var choiceConstraint = params.createIntChoiceConstraint(cArray); 
       params.replaceConstraint("List", choiceConstraint);</task>
       </button>
       <param expand="true" height="452" left="110" oid="List" top="301" width="436"/>
    </abs>


  • 2.  RE: Array to Parameter

    Posted 01-02-2019 13:24

    Well there's two things to this one...

    1: You are trying to push a value pair with an integer identifier into a string array that only contains one set of data.
    So if you want to use a "String Array" you dont need the key/value pair, but just an array of string values.
    You must also use the "params.createStringChoiceConstraint" instead.

    The below example will change the values of the dropdown to your "apples, oranges, bananas.

    <abs contexttype="opengear" gridsize="20" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="STRING_CHOICE" maxlength="0" name="List" oid="List" precision="0" type="STRING_ARRAY" widget="combo">
                <value>String 1</value>
                <constraint>String 1</constraint>
                <constraint>String 2</constraint>
                <constraint>String 3</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="60" left="80" oid="List" showlabel="false" top="80" widget="combo" width="240"/>
       <button buttontype="push" height="80" left="380" name="PUSH" top="80" width="140">
          <task tasktype="ogscript">var testArr = ["Apples", "Oranges", "Bananas"]; 
    
    var choiceConstraint = params.createStringChoiceConstraint(testArr); 
    params.replaceConstraint("List", choiceConstraint);</task>
       </button>
    </abs>

    It does not update the allready selected dropdown value, but if you click the button, then the dropdown, you'll see the new options.


    2: If you want to identify each entry by a number (int) instead, you have to change your parameter into an "Int Array" with "choice constraint".
    As you might notice, now you have a value on each entry pluss the string value.
    Set it to dropdown default or change the widget once placed.

    Then the below code would work (wich is more similar to yours):

    <abs contexttype="opengear" gridsize="20" id="_top">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="List" oid="List" precision="0" type="INT16_ARRAY" value="0" widget="combo">
                <constraint key="0">String 1</constraint>
                <constraint key="1">String 2</constraint>
                <constraint key="2">String 3</constraint>
             </param>
          </params>
       </meta>
       <param expand="true" height="60" left="80" oid="List" showlabel="false" top="80" widget="combo" width="240"/>
       <button buttontype="push" height="80" left="380" name="PUSH" top="80" width="140">
          <task tasktype="ogscript">var testArr = ["Apples", "Oranges", "Bananas"]; 
    var cArray = []; 
    var x = testArr.length; 
    for (var i = 0; i &lt; x; i++) {  
          cArray.push({"key":i,"value":testArr[i]});
    }
    var choiceConstraint = params.createIntChoiceConstraint(cArray); 
    params.replaceConstraint("List", choiceConstraint);</task>
       </button>
    </abs>

    Note: This one will actually change the selected value in the dropdown before opening it again.


    #DashBoard