find associated values in dictionary

113 Views Asked by At

I have a condition where I need to get the taskId value of the dictionary where taskcode is "LIFE_MAX_DAYS". How can I do ?

Dictionary    
replFlag: null (Text)
    taskCode: "LIFE_MAX_DAYS"
    createdBy: "Administrator"
    createdOn: 3/20/2020 1:54 AM EDT
    lastModifiedBy: "Administrator"
    lastModifiedOn: 3/20/2020 1:54 AM EDT
    actionId: null (Number (Integer))
    priorityId: 5
    statusId: null (Number (Integer))
    concatKey: null (Text)
    taskId: 5980
    batchId: null (Number (Integer))
    id: 4
Dictionary
    replFlag: null (Text)
    taskCode: "LIFE_MAX_DAYS"
    createdBy: "Administrator"
    createdOn: 3/20/2020 1:54 AM EDT
    lastModifiedBy: "Administrator"
    lastModifiedOn: 3/20/2020 1:54 AM EDT
    actionId: null (Number (Integer))
    priorityId: 5
    statusId: null (Number (Integer))
    concatKey: null (Text)
    taskId: 5980
    batchId: null (Number (Integer))
    id: 5
1

There are 1 best solutions below

0
On
  • wherecontains finds the indicies where an array value is provided.
  • Furthermore, lists support multi-indexing (e. g. {"a", "b", "c", "d"}[{1, 3}] returns {"a", "c"}).
  • Finally lists support projected indexing (e. g. {{x: 1}, {x: 2}, {x: 3}}.x returns {1, 2, 3})

These three features allow you to do this:

with(
  /* Pull out just the task codes of all the tasks */
  taskCodesOfTasks: listOfTasks.taskCode,
  /* Get the indicies where the task code is what we're looking for */
  indicies: wherecontains("LIFE_MAX_DAYS", taskCodesOfTasks),
  /* Pull out the task data */
  selectedTasks: listOfTasks[indicies],
  /* Return the task IDs */
  selectedTasks.taskId
)

Which can of course be spelled with much less ceremony:

listOfTasks[wherecontains("LIFE_MAX_DAYS", listOfTasks.taskCode)].taskId