need to get null value rows data

I am working on an expression rule. In that rule, I need to get rows with null values as output. I am providing some map inputs like {username: test, fname: test1, lname: test2, email: test@gmail.com, username: test, fname: test1, lname: test2, email: ""}. I want to get the output as: {username: test, fname: test1, lname: test2, email: ""}.  I am getting only null.However, I am unable to get the exact output. Can anyone help me out?.Thanks for your help in adavnce

a!localVariables(
  local!users: a!forEach(
    items: ri!users,
    expression: a!map(
      username: fv!item.username,
      firstname: fv!item.firstname,
      lastname: fv!item.lastname,
      email: fv!item.email
    )
  ),
  local!nullValueUsers: a!forEach(
    items: local!users,
    expression: if(
      or(
        isnull(fv!item.username),
        isnull(fv!item.firstname),
        isnull(fv!item.lastname),
        isnull(fv!item.email)
      ),
      fv!item,
      null
    )
  ),
  local!nulldataValueUsers: reject(fn!isnull, local!nullValueUsers),
  local!nulldataValueUsers
)

###rule input datatype- Map

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    first, you don't need the final "reject" function call - simply return {} instead of null in your original loop (then wrap in a!flatten to handle the case of ALL nulls), and this constructs your final list correctly  (assuming the value you're passing in for "ri!users" was even correct, though you didn't really show us what its value was).

    This is pretty easy to convert into an all-self-contained example, which i've done here. and as you can see, the results are pretty much as-expected.

    a!localVariables(
      local!users: {
        a!map(
          username: "ssmith",
          firstname: "sally",
          lastname: "smith",
          email: "sally@smith.net"
        ),
        a!map(
          username: "mroberts",
          firstname: "",
          lastname: "roberts",
          email: "mike@roberts.net"
        ),
        a!map(
          username: "ajohns",
          firstname: "andrew",
          lastname: "johns",
          email: ""
        )
      },
      local!nullValueUsers: a!flatten(a!forEach(
        items: local!users,
        expression: if(
          or(
            a!isNullOrEmpty(fv!item.username),
            a!isNullOrEmpty(fv!item.firstname),
            a!isNullOrEmpty(fv!item.lastname),
            a!isNullOrEmpty(fv!item.email)
          ),
          fv!item,
          {}
        )
      )),
      
      /*local!nulldataValueUsers: reject(fn!isnull, local!nullValueUsers),*/
      /*local!nulldataValueUsers*/
      
      local!nullValueUsers
    )

Reply
  • 0
    Certified Lead Developer

    first, you don't need the final "reject" function call - simply return {} instead of null in your original loop (then wrap in a!flatten to handle the case of ALL nulls), and this constructs your final list correctly  (assuming the value you're passing in for "ri!users" was even correct, though you didn't really show us what its value was).

    This is pretty easy to convert into an all-self-contained example, which i've done here. and as you can see, the results are pretty much as-expected.

    a!localVariables(
      local!users: {
        a!map(
          username: "ssmith",
          firstname: "sally",
          lastname: "smith",
          email: "sally@smith.net"
        ),
        a!map(
          username: "mroberts",
          firstname: "",
          lastname: "roberts",
          email: "mike@roberts.net"
        ),
        a!map(
          username: "ajohns",
          firstname: "andrew",
          lastname: "johns",
          email: ""
        )
      },
      local!nullValueUsers: a!flatten(a!forEach(
        items: local!users,
        expression: if(
          or(
            a!isNullOrEmpty(fv!item.username),
            a!isNullOrEmpty(fv!item.firstname),
            a!isNullOrEmpty(fv!item.lastname),
            a!isNullOrEmpty(fv!item.email)
          ),
          fv!item,
          {}
        )
      )),
      
      /*local!nulldataValueUsers: reject(fn!isnull, local!nullValueUsers),*/
      /*local!nulldataValueUsers*/
      
      local!nullValueUsers
    )

Children
No Data