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 - Search on generated property

scottmahr - Thursday, May 12, 2011 2:41 PM:

I generate a "ball in court" property at onAfterGet from the current workflow progress.  This works great.  I am trying to search over this using simple search.  No matter what I enter I get no search results.  I am pretty sure this is because when the search criteria is applied, there is nothing in the field (as it is filled in after get).  Any ideas on how to get around this?

 

Thanks,

 

Scott



RobMcAveney - Friday, May 13, 2011 10:50 AM:

As you alluded to, if there is no value in the database Innovator cannot automatically perform the search.  You need an OnBeforeGet method to translate conditions on your federated property into something Innovator can apply against the database.  This logic is basically the inverse of your OnAfterGet logic. It should be pretty straightforward for simple search conditions, but it can get harder when you get into advanced searches (logicals, conditions, etc.).  I would suggest just returning an error if you get criteria you can't handle.

Let's say you had a federated property named recently_added whose value was 1 if the item was created in the past week and 0 otherwise.  Your OnAfterGet would look something like this:

for (int i=0; i<this.getItemCount(); i++)
{
    Item thisItem = this.getItemByIndex(i);
    string createdOn = thisItem.getProperty("created_on","");
    DateTime createdOnDate = DateTime.Parse(createdOn);
    DateTime compareDate = DateTime.Now.AddDays(-7);
    thisItem.setProperty("recently_added", (createdOnDate > compareDate) ? "1" : "0");
}
return this;

and your OnBeforeGet would be something like:

Innovator inn = this.getInnovator();
string recent = this.getProperty("recently_added","");
if (recent == "") return this;
if (recent != "0" && recent != "1") return inn.newError("Invalid search criteria");
DateTime compareDate = DateTime.Now.AddDays(-7);
this.setProperty("created_on",compareDate.ToString("yyyy-MM-ddThh:mm:ss"));
this.setPropertyCondition("created_on",(recent == "0") ? "lt" : "ge");
return this;

In this case the OnBeforeGet is adding criteria on the created_on property to the request in order to limit the results.  Your method will be a bit more complicated, as you'll need to handle wildcards and probably traverse a bunch of relationships.