gridTextColumn

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:

  • 111 = Jon Smith
  • 222 = Sally Jones
  • 333 = James Harris

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

  • I think the user is not valid, can you check if the user is valid or not ,using the function "isusernametaken"

    eg.

    =with(
    if(

    not(isusernametaken(ri!userName)),

    "User Not Available",
    user(ri!userName, "firstName") & " " & user(ri!userName, "lastName")
    )
    )
  • thanks kchaitanyam,

    this is still giving me the below error. It seems the apply function is not working in this use case. Will try another workaround:

    Could not display interface. Please check definition and inputs.

    Interface Definition: Expression evaluation error in rule 'ah_formatusername' at function 'user' [line 3]: Error evaluating function 'user' : [InvalidUserException]

    thank you.

  • 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

  • Ok, The null check is missing, just check for null, it will work fine


    =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"
    )

    )
    )

    )

    Also I check for the Deactivated User, can you please let me know the UserName datatype,
  • 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

  • Oh, the ApprovalString is Invalid: that is why you get the Incorrect user :

    there are multiple UserName in single datasubset as shown on your image,

    you need to split the UserName and use the username

    =with(
    local!UserName : index(split(ri!UserName,","),1,ri!UserName),

    if(
    a!isNullOrEmpty( local!UserName),
    "",
    if(
    not(isusernametaken( local!UserName)),

    "User Not Available",
    if(
    isuseractive( local!UserName),
    user( local!UserName, "firstName") & " " & user( local!UserName, "lastName"),
    "Invalid User"
    )

    )
    )

    )

    hope this work
  • 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.

  • According to your first screenshot, each element in your "approvedString" array is not a single user name. Instead each element is a concatenation of the same username repeated 3 times. In order for your rule to work, each element in your "approvedString" array should contain 1 user name.

    Also, a!isNullOrEmpty() is not a supported function. Please use an alternative, such as isnull().
  • 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)}
    ),

     if(

        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
    )
    )
    )

  • Bishnu,
    Thank you.
    The screenshot I sent with the 3 duplicated usernames is just an example for testing. In production, those 3 usernames will be different. Right now, it should return the same User in an array or size = 3. In production, It will be 3 different users being returned in an array.
    The problem I'm running into is the apply() function. The rule is correctly returning the user details from the indexed location in the array. However, the apply() function is not traversing through the entire array of usernames, instead, its only applying to the first element in the array.
    Any suggestions will be appreciated to workaround this issue with the apply() function.
    thank you!