Facility Control

 View Only
  • 1.  Creating a dropdown with data from Excel or .txt

    Posted 08-18-2018 07:21
    I would like to populate a dropdown list from a Text or Excel file. Can anybody help me with the code that will fetch the data and assign it to a parameter array? It's for teamsheets and player selection for lower thirds.
    (I know it's been asked before, but the tutorial video links seem to be broken and I couldn't find what I was looking for. Thanks very much)


  • 2.  RE: Creating a dropdown with data from Excel or .txt

    Posted 08-26-2018 10:12

    Here is an example, assuming your text file was created like this:

    0,Name 1
    1, Name 2
    2, Name 3
    4, Name 4
    etc.

    Basically a comma-delimited file with each record on its own line.

    You could read it with a function like this:

    function readTextFile(path, oid)
    {
       var textFile = ogscript.createFileInput(path);
       var allText = textFile.readString(textFile.getSize());
       textFile.close();
    
       var entries = [];
      
       var allLines = allText.split("\n");
       for (var i = 0; i < allLines.length; i++)
       {
          ogscript.debug(allLines[i]);
          var record = allLines[i].split(",");
          entries.push({"value": record[1], "key": record[0]});
       }
    
       var newConstraint = params.createStringStringChoiceConstraint(entries);
       params.replaceConstraint(oid, newConstraint);
    }

    Assuming your parameter is defined like this:

    <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="Entries" oid="players" stateless="true" type="STRING" value="0" widget="default">
                <constraint key="0">Player</constraint>
    </param>

    Then you would just call it like this:

    readTextFile("pathtofile.txt", "players"); // where "players" is the oid of the param

    #DashBoard


  • 3.  RE: Creating a dropdown with data from Excel or .txt

    Posted 08-30-2018 08:02
    Thanks very much.
    #DashBoard


  • 4.  RE: Creating a dropdown with data from Excel or .txt

    Posted 04-27-2020 14:06

    Hi Joseph/All, 

     

    I tried following the above and I can't make it work.    This is what I have... what am I missing? 

     

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="Entries" oid="players" type="STRING" value="0" widget="default">
    <constraint key="0">Test</constraint>
    <constraint key="1">Test2</constraint>
    </param>
    </params>
    </meta>
    <param expand="true" height="115" left="193" oid="players" top="350" widget="combo" width="277"/>
    <button buttontype="push" height="62" left="346" name="test" top="240" width="389">
    <task tasktype="ogscript">function readTextFile("d:\list.txt", "players")
    {
    var textFile = ogscript.createFileInput("d:\list.txt");
    var allText = textFile.readString(textFile.getSize());
    textFile.close();

    var entries = [];

    var allLines = allText.split("\n");
    for (var i = 0; i &lt; allLines.length; i++)
    {
    ogscript.debug(allLines[i]);
    var record = allLines[i].split(",");
    entries.push({"value": record[1], "key": record[0]});
    }

    var newConstraint = params.createStringStringChoiceConstraint(entries);
    params.replaceConstraint("players", newConstraint);
    }</task>
    </button>
    </abs>

     


    #DashBoard


  • 5.  RE: Creating a dropdown with data from Excel or .txt

    Posted 04-29-2020 11:10

    A lot is missing.

    First of all, if you want to have a general/global function, you must include that function in an "API" section within the "META" section.

    Secondly, you're including the function in your task but it is not valid OGScript because you're defining the function with constant parameters and then never calling the function.

    Here is an untested but fixed version of what you provided:

    [code]

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <api>

    function readTextFile(path, oid)
    {
    var textFile = ogscript.createFileInput(path);
    var allText = textFile.readString(textFile.getSize());
    textFile.close();

    var entries = [];

    var allLines = allText.split("\n");
    for (var i = 0; i < allLines.length; i++)
    {
    ogscript.debug(allLines[i]);
    var record = allLines[i].split(",");
    entries.push({"value": record[1], "key": record[0]});
    }

    var newConstraint = params.createStringStringChoiceConstraint(entries);
    params.replaceConstraint(oid, newConstraint);
    }
    </api>
    <params>
    <param access="1" constraintstrict="false" constrainttype="STRING_STRING_CHOICE" maxlength="0" name="Entries" oid="players" type="STRING" value="0" widget="default">
    <constraint key="0">Test</constraint>
    <constraint key="1">Test2</constraint>
    </param>
    </params>
    </meta>
    <param expand="true" height="115" left="193" oid="players" top="350" widget="combo" width="277"/>
    <button buttontype="push" height="62" left="346" name="test" top="240" width="389">
    <task tasktype="ogscript">readTextFile("pathtofile.txt", "players"); // where "players" is the oid of the param</task>
    </button>
    </abs>

    [/code]


    #DashBoard


  • 6.  RE: Creating a dropdown with data from Excel or .txt

    Posted 04-29-2020 11:49

    Thank you Joseph. 


    #DashBoard