PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 1/9/2012 8:01 PM by  rogowsky
Test for Blank User Attribute
 5 Replies
Sort:
You are not authorized to post a reply.
Author Messages
Rick Pearl
Private
Basic Member
(14 points)
Basic Member
Posts:8


Send Message:

--
1/6/2012 2:38 PM
    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
    Private
    Private
    Senior Member
    (9899 points)
    Senior Member
    Posts:3317


    Send Message:

    --
    1/6/2012 6:43 PM
    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
    Private
    Basic Member
    (14 points)
    Basic Member
    Posts:8


    Send Message:

    --
    1/9/2012 12:46 PM
    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
    Private
    Private
    Senior Member
    (9899 points)
    Senior Member
    Posts:3317


    Send Message:

    --
    1/9/2012 1:54 PM
    (typeof user.getAttribute('ProcessLevelControl')== 'undefined') || (trim(user.getAttribute('ProcessLevelControl'))== '')
    Thanks for using the LawsonGuru.com forums!
    John
    Rick Pearl
    Private
    Basic Member
    (14 points)
    Basic Member
    Posts:8


    Send Message:

    --
    1/9/2012 7:58 PM
    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
    developer
    city of nashua
    Basic Member
    (13 points)
    Basic Member
    Posts:5


    Send Message:

    --
    1/9/2012 8:01 PM
    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
    You are not authorized to post a reply.