dennis - Wednesday, July 6, 2011 2:02 PM:
I have a piece of method code that runs a get with criteria. Immediately after running the get the code checks the isError property and if true then returns the error. In a particular use case, the get does not return any results. I have found that no results leads to isError being true on the result after the apply. I have never noticed this before. Is this normal behavior? Here is a code snippet.
Item affectedItemsAllGens;
affectedItemsAllGens = this.newItem("Change Controlled Item","get"); affectedItemsAllGens.setAttribute("select","config_id,keyed_name,generation,state,itemtype"); affectedItemsAllGens.setAttribute("order_by","config_id,generation"); affectedItemsAllGens.setProperty("generation","*"); affectedItemsAllGens.setPropertyCondition("generation","like"); affectedItemsAllGens.setProperty("config_id",configList.ToString()); affectedItemsAllGens.setPropertyCondition("config_id","in");
affectedItemsAllGens.setProperty("state", "'Development','Engineering Ready','Validation','Validation Change Pending','Deployment','Deployment Change Pending'");
affectedItemsAllGens.setPropertyCondition("state", "in");
affectedItemsAllGens = affectedItemsAllGens.apply();
//isError is true when apply does not return results. The getErrorString value is "No items of type Change Controlled Item found."
if (affectedItemsAllGens.isError())
{ return inn.newError("There was an error returning all generations of the affected items.<br>" + affectedItemsAllGens.getErrorDetail()); }
I don't want to return an error because the get did not return results. What are some options for catching a real error versus when the get does not return results?
Brian - Thursday, July 7, 2011 11:41 PM:
Hi Dennis,
You can test "affectedItemsAllGens.isEmpty()". This will return true when nothing has been found but the AML was still valid. Or you can check getItemCount(). It will be 0 for a "get" that returned no results or -1 for a "get" that returned an error due to some legitimate reason.
Hope this helps,
Brian.
dennis - Friday, July 8, 2011 10:57 AM:
{
return inn.newError("Error:<br><br>" + affectedItemsAllGens.getErrorDetail());
}
// "No Items found" case
else if(affectedItemsAllGens.isError())
{
return inn.newResult(affectedItemsAllGens.getErrorDetail());
}