Skip to main content
venkataharishd0002
Inspiring
February 5, 2021
Question

need convert the code having nested If conditions to Foreach()

Hi Team,

Could you please help me in converting the following code into Foreach()

if(
          isnull(
            local!region
          ),
          if(
            rule!APN_isEmpty(
              tostring(
                index(
                  local!userlist.data,
                  "regionId",
                  {}
                )
              )
            ),
            if(
              rule!APN_isEmpty(
                tostring(
                  index(
                    local!userlist.data,
                    "lobId",
                    {}
                  )
                )
              ),
              if(
                rule!APN_isEmpty(
                  tostring(
                    index(
                      local!userreg.data,
                      "regionId",
                      {}
                    )
                  )
                ),
                {},
                local!distuserregname
              ),
              null
            ),
            tostring(
              rule!CTR_QE_getRegionNameByRegionId(
                index(
                  local!userlist.data,
                  "regionId",
                  {}
                )
              )
            )
          ),
          local!region
        )

Thanks in advance.

    1 reply

    venkataharishd0002
    Inspiring
    February 5, 2021

    My issue got resolved with the following query.

    a!forEach(
            items: local!userlist.data,
            expression: if(
              isnull(
                local!region
              ),
              if(
                rule!APN_isEmpty(
                  tostring(
                    index(
                      fv!item,
                      "regionId",
                      {}
                    )
                  )
                ),
                if(
                  rule!APN_isEmpty(
                    tostring(
                      index(
                        fv!item,
                        "lobId",
                        {}
                      )
                    )
                  ),
                  if(
                    rule!APN_isEmpty(
                      tostring(
                        index(
                          local!userreg.data,
                          "regionId",
                          {}
                        )
                      )
                    ),
                    {},
                    local!distuserregname
                  ),
                  null
                ),
                tostring(
                  rule!CTR_QE_getRegionNameByRegionId(
                    index(
                      fv!item,
                      "regionId",
                      {}
                    )
                  )
                )
              ),
              local!region
            ),
          )