This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DEVELOPERS FORUM - Get action with criteria resulting in no matching records sets isError = true

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:

 

Thank you for your response Brian. It will help in my future development work. I also submitted the issue to support as it seems a bit strange for Innovator to set isError to true for no results. This is the response that I received. 
I have filed this issue as IR-016103 in myInnovator.com.
You can use the following code to check if the error returned is due to no Items being found: 
// Check for error other than "No items found"
if(affectedItemsAllGens.isError() &&affectedItemsAllGens.getErrorDetail().Substring(0,16) != "No items of type")
{
  return inn.newError("Error:<br><br>" + affectedItemsAllGens.getErrorDetail());
}
// "No Items found" case
else if(affectedItemsAllGens.isError())
{
  return inn.newResult(affectedItemsAllGens.getErrorDetail());
}