Skip to main content
1-Visitor
August 4, 2015
Solved

Getting results from CLI command inside a script

  • August 4, 2015
  • 2 replies
  • 3764 views

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!

    Best answer by 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!

    2 replies

    16-Pearl
    August 4, 2015

    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

    sknopp1-VisitorAuthor
    1-Visitor
    August 5, 2015

    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

    1-Visitor
    August 5, 2015

    Hi,

    what is your Use Case?

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

    sknopp1-VisitorAuthorAnswer
    1-Visitor
    August 5, 2015

    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!

    16-Pearl
    August 5, 2015

    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

    1-Visitor
    September 7, 2021

    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