Querying from local data

Hi All,

I have queried the data from table and have stored in some local variable.

User have option to select three values: LOB2,LOB3,LOB4. Now based on these selected values i have to query the id

please help me to make changes in the below code to achieve the same.

a!localVariables(
local!data:{
{id:1,lob2:"Commercial Banking", lob3:null ,lob4:null},
{id:2,lob2:"Commercial Banking", lob3:"Commercial Banking" ,lob4:null},
{id:3,lob2:"Commercial Banking", lob3:"Commercial Banking" ,lob4:"CMB"},
{id:4,lob2:"Commercial Banking", lob3:"Commercial Banking" ,lob4:"GPB"},
{id:5,lob2:"Commercial Banking", lob3:"Commercial Banking" ,lob4:"RBWM"},
{id:6,lob2:"Commercial Banking", lob3:"Commercial Banking" ,lob4:"HOST"}
},


local!selectedLOB2:"Commercial Banking",
local!selectedLOB3:"Commercial Banking",
local!selectedLOB4:"GPB",

local!id:index(
local!data.id,
{
wherecontains(local!selectedLOB2, touniformstring(index(local!data,"lob2",null))),
wherecontains(local!selectedLOB3, touniformstring(index(local!data,"lob3",null))),
wherecontains(local!selectedLOB4, touniformstring(index(local!data,"lob4",null)))
}
),
local!id

).

I need suggestion on the highlighted text so that the output should come 4.

--

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Your index() call ends up passing in all members of the array multiple times - the whole set, then all the lob3 matches, then the one lob4 match.  What you should be doing is getting the indices (if necessary) using your whereContains lines, and then finding the items in the original array that match all 3 (though it seems you could just look up the position of the match in lob4, with the current data set anyway).

  • 0
    Certified Lead Developer
    in reply to Mike Schmitt

    For example:

    a!localVariables(
      local!data:{
        {id:1, lob2:"Commercial Banking", lob3:null ,lob4:null},
        {id:2, lob2:"Commercial Banking", lob3:"Commercial Banking", lob4:null},
        {id:3, lob2:"Commercial Banking", lob3:"Commercial Banking", lob4:"CMB"},
        {id:4, lob2:"Commercial Banking", lob3:"Commercial Banking", lob4:"GPB"},
        {id:5, lob2:"Commercial Banking", lob3:"Commercial Banking", lob4:"RBWM"},
        {id:6, lob2:"Commercial Banking", lob3:"Commercial Banking", lob4:"HOST"}
      },
    
      local!selectedLOB2: "Commercial Banking",
      local!selectedLOB3: "Commercial Banking",
      local!selectedLOB4: "GPB",
    
      local!lob2Indices: wherecontains(local!selectedLOB2, touniformstring(index(local!data,"lob2",null))),
      local!lob3Indices: wherecontains(local!selectedLOB3, touniformstring(index(local!data,"lob3",null))),
      local!lob4Indices: wherecontains(local!selectedLOB4, touniformstring(index(local!data,"lob4",null))),
      
      /* have to do a nested intersection here since intersection() only accepts 2 arrays */
      local!matchAllIndices: intersection(
        local!lob2Indices,
        intersection(
          local!lob3Indices,
          local!lob4Indices
        )
      ),
      
      local!id: index(
        local!data.id,
        local!matchAllIndices
      ),
      
      local!id
    )