Hi,
I have the following code:
a!gridTextColumn( label: "Approved By", field: "approvedString", data: index(local!datasubset.data,"approvedString", null))
That returns a text array:
111, 222, 333
I want to send each of these array elements to expression rule!convertID that will convert it to a username.
For example:
Please can someone please tell me the syntax to apply the the rule!convertID to each element returned by data: index(local!datasubset.data,"approvedString", null))?
Thank you.
Discussion posts and replies are publicly visible
Hi Vinay, thank you for the suggestion.
I created a rule with the example code you provided, and now get the below error. I think there's some issue with using apply() in this scenario -any recommendations for a workaround will be appreciated:
RULE: TVP_getNamefromUsername
=with(
if(
not(isusernametaken(ri!userName)),
"User Not Available",
user(ri!userName, "firstName") & " " & user(ri!userName, "lastName")
)
SAIL COMPONENT:
a!gridTextColumn(label: "Approved By",field: "approvedString",data: apply(rule!TVP_getNamefromUsername(_),index(local!datasubset.data,"approvedString",null)))
ERROR:
Interface Definition: Expression evaluation error in rule 'tvp_getnamefromusername' at function 'user' [line 7]: Error evaluating function 'user' : Null argument not allowed
Thank you Vinay,
It is now handling NULL correctly. But still not evaluating valid usernames correctly.
Here is SAIL Component Code:
a!gridTextColumn( label: "approvedString", field: "approvedString", data: index( local!datasubset.data, "approvedString", null ) ), a!gridTextColumn( label: "Approved By", field: "approvedString", data: apply( rule!TVP_getusersname( _ ), index( local!datasubset.data, "approvedString", null ) ) )
Here is a sample of what is returned:
This is what the username 206504472 returns in the rule:
Can you suggest why valid username array is returning "User Not Available"?
Thank you
Thank you Vinay, yes this is returning the correct user BUT only the FIRST user in the array. The apply() is not working. Can you suggest a way to return an array with all users?
Here is the result:
Here is the component:
a!gridTextColumn( label: "Approved By", field: "approvedString", data: apply( rule!TVP_getusersname( _ ), index( local!datasubset.data, "approvedString", null ) ) )
Many thanks for all your help.
Ok the apply is correct, but you need to call apply two time, 1) Expression: GetUserNames Input : UserName Text Definition: =with(
local!UserNameArray: apply( rule!TVP_getusersname( UserName:_ ), {index(split(ri!UserName,","),1,ri!UserName)} ),
a!isNullOrEmpty(local!UserNameArray),"",
joinarray(
local!UserNameArray,","
) 2) Expression: TVP_getusersname Input : UserName Text Definition: =with( if( a!isNullOrEmpty(ri!UserName), "", if( not(isusernametaken( ri!UserName)), "User Not Available", if( isuseractive( ri!UserName), user( ri!UserName, "firstName") & " " & user( ri!UserName, "lastName"), "Invalid User" ) ) ) ) 3) On SAIL a!gridTextColumn( label: "Approved By", field: "approvedString", data: apply( rule!GetUserNames( _ ), index( local!datasubset.data, "approvedString", null ) ) )
One issue I see immediately with your apply function (and which everyone else here so far has missed) is that you're returning "null()" as the default result of your index() function inside the data: parameter of a!gridTextColumn. There's a chance this won't do anything bad, but in the case where your datasubset is empty (or filtered down to empty), null() will cause an error -- you should always use the empty set ("{}") there instead. Also you should really call out the rule input specifically when you apply() over your helper rule.
The result of my 2 suggested changes would look like this:
a!gridTextColumn( label: "Approved By", field: "approvedString", data: apply( rule!TVP_getusersname( userName: _ ), index( local!datasubset.data, "approvedString", {} ) ) )