javascript to read both the display and list value selecting in a combobox

I have a form with a combox. Input is $my.QA1, Display list is 'Yes;No;Na' and the Value List is '3;1;0'

user choses Yes.

script reads $my.QA1 and gets 3. so that's good.

I also need to read the display value, 'Yes' and I can't seam to find a way to read it. I have 22 risk questions on a form with weights to calculate a change records risk. so every question has a Value list, a Display list, and a weight (eg 0.25, 0.40 ...) so that I can weight each answer and sum to a score. than I write the Risk review to a Risk Description and need the question ,answer, and weighted score. I know the questions text, I know the weight, I read the Value, calculate the score but can't read or show what the user picked (Yes, No or NA). Any Ideas?

 

  • Unfortunately, the display list/value list is completely managed at the form level.  It's basically a mask that lays on top of the data in the field, to display some value based on the actual value within the field on the screen.  

    If you used global variables in your display list/value list, you can do a lookup on the $G variable and find the display list value based on the position of the answer... 

    For example, if you've got a global list for your QA1 question with the value list variable as $G.QA1.values and the display list variable as $G.QA1.display, you'd end up with two arrays:
    $G.QA1.values={"3", "1", "0"}
    $G.QA1.display={"Yes", "No, "Na"}

    Then you could use the index function to figure out the placement of the value in the $my.QA1 and pull the display value from that same position.  So, for example, if the value of $my.QA1=3, it would see 1 as the position of that value in the values array, and then you could set something to use the first element of your display array.

    Using standard HPSM script language that would be:
    $L.idx = index($my.QA1,$G.QA.values)
    $my.QA1.display = $L.idx in $G.QA.display

    Using javascript that would be more like
    var idx = vars.$G_QA_values.indexOf(vars.$my_QA1)
    vars.$my_QA1_display = vars.$G_QA1_display[idx]

    Otherwise, if you're not using global lists, you could create variables within the JavaScript itself to store the arrays of value lists and displays lists

  • Just getting back to see the answer. I watched it for a day but I ran out of design time.

    That's what I ultimatly decided to do. float the format, bind everything to a scalars, and load from ScriptLib. that way the format only knows layout of lables, textboxs and combos but no values. Each has a logical variable. $my.Q{A,W,D,L}n

    So the first record on the form binds to these variables to produce a question with options and weighted scores.

    $my.Q1 = label ; $my.QA1 =  answer; $my.QW1 = weight, $my.QD1 = display values; $my.QL1 = list value

    Script Library controls everything and all the data and values come from an array. eval works great and I don't see much of a speed penalty. the code is very portable (1 format, 1 SL, 1 script, 2 DO) and controls 105 values using only 3 fields in the cm3r table. a traditional design would have required 66 new fields to be added to the cm3r table (or new table(s)) and I just couldn't do that to myself.

    clip of the loader (aka display). Save works the same and allows version control and Edit old records.

    function LoadValues() {
    var loadLast = false;
    var valString = system.functions.nullsub(system.vars.$file.dlt_risk_answers,"");
    if(valString.indexOf(";")>=0) //try and load old answers
    {
    var valArray= valString.split(";");
    //saved answer need to be the same version as questions
    if (valArray[0]==QV1[0][0]) loadLast = true;
    }
    //form controls can't read arrays so we must declair scalars in the thread.
    for (var i = 1; i < QV1.length; i ) { //populate form and loadLast if true.
    eval("vars.$my_Q" i "= QV1[" i "][0]");
    eval("vars.$my_QW" i "= QV1[" i "][1]");
    if (loadLast) { //try and set
    valArray[i] = eval(valArray[i]); //eval out any strings and null cast NULL.
    eval("vars.$my_QA" i "= valArray[i]");
    } else {
    eval("vars.$my_QA" i "= null");
    }
    eval("vars.$my_QD" i "= eval(QV1[" i "][2])");
    eval("vars.$my_QL" i "= eval(QV1[" i "][3])");
    //print(eval("vars.$my_Q" i));
    }

    }

    I'll give you a Kudo for thinking the same. :-)