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

Community Tip - When posting, your subject should be specific and summarize your question. Here are some additional tips on asking a great question. X

Looking for script example for parsing response of Java API.

smccoy
12-Amethyst

Looking for script example for parsing response of Java API.

I'm hoping that this has been done 1000's of times and someone has an example to share.

I need to parse the response from a JavaAPI call from a trigger script.

Example:



var cmd = new Packages.com.mks.api.Command("im","issues");


cmd.addOption(new Packages.com.mks.api.Option("queryDefinition", queryDefinition));


var response = api.executeCmdAs(currentUser, cmd);
2 REPLIES 2
mrump
16-Pearl
(To:smccoy)

Hi Sean,

Here's a snippet that shows the general concept.

The JAVA API is used identically in a trigger script, as it would be used in POJ application.

HTH Matthias

/**

* creates the Command to Run the temporary Query

* @return Packages.com.mks.api.Command queryCommand

*/

function getRunQueryCommand()

{

var queryCommand = new Packages.com.mks.api.Command(Packages.com.mks.api.Command.IM, "issues");

queryCommand.addOption(new Packages.com.mks.api.Option("fields", "Type,ID"));

var queryBuf = new java.util.StringBuffer();

queryBuf.append('(');

queryBuf.append("field[");

queryBuf.append(singletonField);

queryBuf.append("]=");

queryBuf.append(currentValue);

queryBuf.append('"');

queryBuf.append(')');

queryCommand.addOption(new Packages.com.mks.api.Option("queryDefinition", queryBuf.toString()));

return queryCommand;

}

/**

* check whether the temp query finds at least one Item of the same Type as the current Item

* @return true if successful; false in the event of a failure

*/

function check4Singleton()

{

// Create an API Object to run IM Command Line commands

var api = environmentBean.createAPISessionBean();

// Execute the Query command

var runQueryOut = api.executeCmd(getRunQueryCommand());

if( runQueryOut.getExitCode() == 0 ){

logDebug("Successfully run temporary Query");

// analyse result

if (runQueryOut.getWorkItemListSize() == 0 ){

logDebug("nothing found");

return true;

}

else{

var iter = runQueryOut.getWorkItems()

while (iter.hasNext()) {

var workitem = iter.next()

var tempID = workitem.getField("ID").getValueAsString()

// ########################

// add your own code here

}

return true;

}

}

else{

print("Failed to run temporary Query");

logDebug("leave check4Singleton()");

return false;

}

}

smccoy
12-Amethyst
(To:mrump)

Hi Matthias,

Thank you for the quick reply. I'll check this out as soon as I can (like early next week). I've been handed a set of higher-priority tasks to tackle.

Best of thoughts...

-Sean

Announcements


Top Tags