cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Im getting JavaScript Error in a IM trigger

aharms
2-Explorer

Im getting JavaScript Error in a IM trigger

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

ACCEPTED SOLUTION

Accepted Solutions
mrump
16-Pearl
(To:aharms)

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

}

View solution in original post

5 REPLIES 5
mrump
16-Pearl
(To:aharms)

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

aharms
2-Explorer
(To:mrump)

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

mrump
16-Pearl
(To:aharms)

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

}

Hello Matthias Rump‌,

If you look at the JavaDoc followed from the Event Trigger Java Documenation off of most server's home pages, the method getExposedName() of a given class will tell you the name of the bean used for bsf.lookupBean(String foo).  In this case, it's mks.ci.server.engine.LocalTriggerManager.ScriptUserBean.

Regards,
Kael


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager
aharms
2-Explorer
(To:mrump)

That is exactly what I am looking for.

Thank you very much.

Announcements


Top Tags