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
If you are looking to identify the empty email field, isnull() does not help. isNullOrEmpty() might be what you are looking for.
For more insights on null checking: appian.rocks/.../
output still same :List of Text String - 1 item
Can you share a fully working example, including data?
Is your 'local!users' assignment done by the time you are looping through for the local!nullValueUsers assignment? Does anything change if you were to use ri!users directly on line 12 instead of the local!users?
If this is what you looking for then I can say your conditions are correct but, you need to change the indexing in local!users .In your input map you have first name as fname and Last name as lname but you are indexing them wrong.
Other wise just like stefan mentioned we need more details
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 )