I have observed unexpected behavior for isusernametaken function. When we pass a

I have observed unexpected behavior for isusernametaken function. When we pass an empty string to it, it returns true.
As per my understanding this should not be the case. isusernametaken should return true for only the users which exist (activated/deactivated) in the system. This was observed on Appian 7.11
fn!isusernametaken("") - true

OriginalPostID-205763

OriginalPostID-205763

  Discussion posts and replies are publicly visible

Parents
  • fn! doesn't have side effects, meaning if should always return expected value. isusernametaken() is a bool, and think of passing null as divided by 0. What should happen, when your only possible return value is a number?

    One of the purposes is you should be able to create users based on output of this function, if it returns false for null creating the user fails.

    As @stefanh791 mentioned, use a wrapper to check for null.

    For more context, from Appian common objects rule!APN_displayUser, it checks for null ahead, as I said earlier, fn! functions should have no side effects, so check for null and handle accordingly:

    if(isnull(ri!user), "",
    if(isusernametaken(ri!user),
    user(ri!user, "firstName") & " " & user(ri!user, "lastName"),
    tostring(ri!user)
    ))
Reply
  • fn! doesn't have side effects, meaning if should always return expected value. isusernametaken() is a bool, and think of passing null as divided by 0. What should happen, when your only possible return value is a number?

    One of the purposes is you should be able to create users based on output of this function, if it returns false for null creating the user fails.

    As @stefanh791 mentioned, use a wrapper to check for null.

    For more context, from Appian common objects rule!APN_displayUser, it checks for null ahead, as I said earlier, fn! functions should have no side effects, so check for null and handle accordingly:

    if(isnull(ri!user), "",
    if(isusernametaken(ri!user),
    user(ri!user, "firstName") & " " & user(ri!user, "lastName"),
    tostring(ri!user)
    ))
Children
No Data