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

Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X

Getting results from CLI command inside a script

sknopp
1-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
sknopp
1-Newbie
(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
KaelLizak
14-Alexandrite
(To:sknopp)

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

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
4-Participant
(To:sknopp)

Hi,

what is your Use Case?

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

sknopp
1-Newbie
(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!

KaelLizak
14-Alexandrite
(To:sknopp)

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
EP_9964574
6-Contributor
(To:KaelLizak)

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

Top Tags