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

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

Getting results from CLI command inside a script

sknopp
12-Amethyst

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!

ACCEPTED SOLUTION

Accepted Solutions
sknopp
12-Amethyst
(To:sknopp)

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

6 REPLIES 6

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
sknopp
12-Amethyst
(To:KaelLizak)

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

tketz
12-Amethyst
(To:sknopp)

Hi,

what is your Use Case?

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

sknopp
12-Amethyst
(To:sknopp)

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!

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

Hello, I need to call powershell script / vbs script from triggered javascript. I tried to use ActiveXObject but throws error stating 'ActiveXObject not defined'. any other way to call scripts using javascript? Thanks

Announcements


Top Tags