Store dropdown label in variable (not index value)

I have a script that will read a CSV file, and update a record. One of them is a dropdown list. So after updating the record, I would like to check if the changes were saved. I compare the values from the CSV and read the values on the page. For dropdowns, what I end up getting in the variable is the dropdown value, instead of the label. Is there an easy way to read the label instead?

I created a simple example

HTML
KantuTest

Kantu

{
  "Name": "KantuTest",
  "CreationDate": "2019-9-10",
  "Commands": [
    {
      "Command": "open",
      "Target": "http://engta.faith/test/KantuTest.html",
      "Value": ""
    },
    {
      "Command": "select",
      "Target": "name=selectedTask.StatusID",
      "Value": "label=Investigating"
    },
    {
      "Command": "storeValue",
      "Target": "name=selectedTask.StatusID",
      "Value": "varTaskStatus"
    },
    {
      "Command": "echo",
      "Target": "Task Status: ${varTaskStatus}",
      "Value": ""
    }
  ]
}

Using storeValue, I’m getting the index (2). I’m hoping to be able to store the value instead (Investigating) because what I have in the CSV source is “Investigating”. My goal is to check:

${varTaskStatus} == ${varCSVTaskStatus}

Right now, that’s

2 == Investigating

so it won’t match.

If not possible, is there a one-line javascript you can suggest where I can convert my index ID to a corresponing label (something like a VLOOKUP in Excel).

Assuming there’s no easy way, I used a Javascript to solve my problem. Would welcome any simpler solution:

The one-line JS:

var tblCode = ['APL','BAN','GRP','ORG']; var tblName = ['Apple','Banana','Grapes','Orange']; var varIndex = tblCode.findIndex(function(varElement) {return varElement == ${varCode}; }); return tblName[varIndex]

Sample macro

{
  "Name": "js-2",
  "CreationDate": "2019-9-11",
  "Commands": [
    {
      "Command": "comment",
      "Target": "storeValue // name=selectedTask.statusId",
      "Value": "varIndex"
    },
    {
      "Command": "store",
      "Target": "GRP",
      "Value": "varCode"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var tblCode = ['APL','BAN','GRP','ORG']; var tblName = ['Apple','Banana','Grapes','Orange']; var varIndex = tblCode.findIndex(function(varElement) {return varElement == ${varCode}; }); return tblName[varIndex]",
      "Value": "varResult"
    },
    {
      "Command": "echo",
      "Target": "Variable = ${varResult}",
      "Value": ""
    }
  ]
}

Using objects in lieu of arrays

var objTbl = {'APL': 'Apple', 'BAN': 'Banana', 'GRP': 'Grape'}; return objTbl[${varCode}];

Sample

{
  "Name": "obj-1",
  "CreationDate": "2019-9-11",
  "Commands": [
    {
      "Command": "comment",
      "Target": "storeValue // name=selectedTask.statusId",
      "Value": "varIndex"
    },
    {
      "Command": "store",
      "Target": 'GRP',
      "Value": "varCode"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "var objTbl = {'APL':  'Apple', 'BAN': 'Banana', 'GRP': 'Grape'}; return objTbl[${varCode}];",
      "Value": "varResult"
    },
    {
      "Command": "echo",
      "Target": "Variable = ${varResult}",
      "Value": ""
    }
  ]
}