Test for Blank User Attribute

 5 Replies
 0 Subscribed to this topic
 15 Subscribed to this forum
Sort:
Author
Messages
Rick Pearl
Basic Member
Posts: 8
Basic Member
    How do you test for a user attribute that is blank/empty?

    I have tried user.getAttribute('ProcessLevelControl') == ''  and trim(user.getAttribute('ProcessLevelControl')) == ''

    Neither of which work.

    If anyone knows the trick, I would appreciate it.

    thanks!
    John Henley
    Posts: 3353
      Blank vs. empty might return different results. If my experience is correct, Lawson RM only creates the attribute values when they are populated, so I'm guessing the rules engine probably returns lack of a value as an undefined variable. So you might want to try putting the attribute value into a variable and then seeing if it returns as undefined.
      var plc = trim(user.getAttribute('ProcessLevelControl');
      if ( (typeof plc == 'undefined') || (plc == '') )
      ...
      Thanks for using the LawsonGuru.com forums!
      John
      Rick Pearl
      Basic Member
      Posts: 8
      Basic Member
        Hi John, thanks for the reply!

        I am trying to do this as a security class rule in Lawson Security Administrator.   I am a relative newbee to this but I don't think I can use variables that way in a security class rule.  All the statements exist inside the If statement.  How would you get the variable assignment  before the if statement?


        John Henley
        Posts: 3353
          (typeof user.getAttribute('ProcessLevelControl')== 'undefined') || (trim(user.getAttribute('ProcessLevelControl'))== '')
          Thanks for using the LawsonGuru.com forums!
          John
          Rick Pearl
          Basic Member
          Posts: 8
          Basic Member
            Thanks John.

            The secret did turn out to be the 'typeof' function, but not comparing to 'undefined'.  I tried, 'undefined', ''null' and I also tried to check for a length of < 3.  Nof of which worked.  However, checking for a typeof 'string' worked.  If the attribute does not contain a value, it is not a typeof 'string'.  If it has a value, it is a typeof 'string'.
            rogowsky
            Basic Member
            Posts: 5
            Basic Member
              Hi Rick,

              When all else fails, try this...
              (typeof user.getAttribute('ProcessLevelControl') != 'string')
              to test for a blank attribute.

              We may not know what getAttribute is returning, but if it does not return a string type, then you do not have a value for that attribute.

              Marcia