Skip to main content
1-Visitor
May 20, 2016
Solved

Im getting JavaScript Error in a IM trigger

  • May 20, 2016
  • 1 reply
  • 4013 views

Hi,

I am trying to get the User Object from imUserBean, but I think it cannot be created: JavaScript Error: Internal Error: undefined: Cannot convert null to an object

function main()

{

    if(delta.isNewlyPosted() && delta.getNewFieldValue("Severity") == null){

        abort(user.getFullName());

    }

}

var delta = bsf.lookupBean("imIssueDeltaBean");

var eb = bsf.lookupBean("siEnvironmentBean");

var user = bsf.lookupBean("imUserBean");

main();

So I am trying to create the object with bsf.lookupBean and then abort the action with the full name of the user who caused this action.

Instead I get the error in the line (bold).

Thanks in advance

Alexander

    Best answer by mrump

    There is a difference between user beans from the Integrity Manager (Workflow & Documents) and the Domain Users.

    Unfortunately both use a Bean called .....ScriptUserBean

    • mks.si.brain.triggers.beans.ScriptUserBean
    • mks.ci.server.engine.LocalTriggerManager.ScriptUserBean

    I'm not sure with one is returned by

    bsf.lookupBean("imUserBean")

    Nevertheless, every time I tried to solve a task like your's in the past I ended up using the following template:

    //get the Server bean

    var sb = bsf.lookupBean("imServerBean");

    // get the bean representing the current item

    var delta = bsf.lookupBean("imIssueDeltaBean");

    // fetch the user name from the current item's bean e.g.

    var currentUserName = delta.getCurrentUser();

    // retrieve the matching user bean from the server

    var userbean = sb.getUserBean(currentUserName);

    // analyze the user bean

    if( userbean.isMember("a Group") == true ){

      // do something

    }

    1 reply

    16-Pearl
    May 20, 2016

    HI Alex,

    i assume your user is null, as

         var user = bsf.lookupBean("imUserBean");

    ives you an undefined user bean.

    I'd choose someting like this:

    var user = delta.getCurrentUser();

    or

    var user = delta.getCreatedUser();

    or

    var user = delta.getModifiedUser();

    given your use case, they should all return the same user.

    HTH Matthias

    aharms1-VisitorAuthor
    1-Visitor
    May 20, 2016

    Hi,

    thank you for your reply.

    Iis not described in my question, but I need furthermore the group of the user, not only his name.

    I want to try something like this:

    var user = bsf.lookupBean("imUserBean");

    if(user.isMember("Some_group")){

         abort("foo");

    }

    I dont understand why this bean is empty or null. Because I use a Domain User who is imported into Workflows&Documents. It must have bean for IM user...

    Any other idea how to get the user and its groups or membership of a specific group?

    Thank you

    mrump16-PearlAnswer
    16-Pearl
    May 23, 2016

    There is a difference between user beans from the Integrity Manager (Workflow & Documents) and the Domain Users.

    Unfortunately both use a Bean called .....ScriptUserBean

    • mks.si.brain.triggers.beans.ScriptUserBean
    • mks.ci.server.engine.LocalTriggerManager.ScriptUserBean

    I'm not sure with one is returned by

    bsf.lookupBean("imUserBean")

    Nevertheless, every time I tried to solve a task like your's in the past I ended up using the following template:

    //get the Server bean

    var sb = bsf.lookupBean("imServerBean");

    // get the bean representing the current item

    var delta = bsf.lookupBean("imIssueDeltaBean");

    // fetch the user name from the current item's bean e.g.

    var currentUserName = delta.getCurrentUser();

    // retrieve the matching user bean from the server

    var userbean = sb.getUserBean(currentUserName);

    // analyze the user bean

    if( userbean.isMember("a Group") == true ){

      // do something

    }