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

Getting results from CLI command inside a script

SOLVED
Highlighted
Newbie

Getting results from CLI command inside a script

Hi,

i want to get the email address from a user inside a trigger script using the Integrity API. I've used mksapiviewer --iplocal im users --fields=email USERNAME to check if there is an output at all and it returned a response including a work item containing the field "Value" where the address is stored. I've tried

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

var apibean = eb.createAPISessionBean();

var command = new Packages.com.mks.api.Command("im", "users");

command.addOption(new Packages.com.mks.api.Option("fields", "email");

command.addSelection(USERNAME);

var response = apibean.executeCmd(command);

var workitems = response.getWorkItems();

while(workitems.hasNext()){

   var thisItem = workitems.next();

   var val = thisItem.getField("Value");

}

Somewhere has to be a mistake since i get a NoSuchElementException: Value

Does somebody have an idea where the problem is??

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Getting results from CLI command inside a script

Hi,

found the solution myself. I got confused with the fields inside the response, so using

var fld = thisItem.getField("notificationRule");

var val = fld.getValueAsString();

returns the Notification Rule as a string!

But thanks for your input!

View solution in original post

5 REPLIES 5

Re: Getting results from CLI command inside a script

Hello Stephan,

Whenever possible, you should attempt to use trigger beans rather than API calls from within a trigger.  In this case, instead of your API call, you should call getEmailAddress() on an instance of ScriptUserBean.

You can get a ScriptUserBean for any user on the server by calling the getUserBean(<UserName>) on a ServerBean.

Regards,
Kael


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager

Re: Getting results from CLI command inside a script

Hi,

this may work for getting the email address, but there will be several other steps like getting the Notification Rule of the user, which I doubt can be done by using trigger beans alone. But thanks anyway!!

Stephan

Re: Getting results from CLI command inside a script

Hi,

what is your Use Case?

The notification rule of a user can found in the Admin Gui (W&D-Users).

Re: Getting results from CLI command inside a script

Hi,

found the solution myself. I got confused with the fields inside the response, so using

var fld = thisItem.getField("notificationRule");

var val = fld.getValueAsString();

returns the Notification Rule as a string!

But thanks for your input!

View solution in original post

Re: Getting results from CLI command inside a script

Hi Stephan,

I'm glad you figured it out yourself!  You should mark your own answer as correct, then, since it's the one that actually answers your question. 

Thanks for coming back and letting everyone know what that answer was!

Regards,

Kael


Kind Regards,
Kael Lizak

Senior Technical Support Engineer
PTC Integrity Lifecycle Manager