Community Tip - You can change your system assigned username to something more personal in your community settings. X
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); |
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;
}
}
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