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 - Specify search on property

handpuppet - Monday, July 20, 2015 11:27 AM:

I have an ItemType named "Document" that has a property called "project".  The project property is itself an item that has an ItemType as its data source.  I attempt to set an Item below and specify the search term I want which is "FCF".  All I get is an error saying "Not a single Item" and I cannot figure out what I have wrong.  Any help greatly appreciated!

Item query = this.newItem("ThisProject", "get");

query.setProperty("project_name", "FCF");

query = query.apply();

this.setProperty("project", query.getProperty("project_name"));

this.setPropertyCondition("project","in");

return this;



zahar - Monday, July 20, 2015 12:55 PM:

Use the ID of the project and not it's name:

Item query = this.newItem("ThisProject", "get");

query.setProperty("project_name", "FCF");

query = query.apply();

if (query != null && !query.isError() && query.getItemCount() > 0) {

this.setProperty("project", "'", query.getItemByIndex(0).getID() , "'");

this.setPropertyCondition("project","in");

}

return this;



handpuppet - Monday, July 20, 2015 1:21 PM:

This worked, thank you very much!

My only other question would be, is there any way to set the property "project_name" with more than one value?  Currently, I just have the value "FCF" which works.  I tried several different ways to add a second value with no success.



zahar - Monday, July 20, 2015 1:27 PM:

Item query = this.newItem("ThisProject", "get");

query.setProperty("project_name", "'FCF'");

query.setPropertyCondition("project","in");

query = query.apply();

 

if (query != null && !query.isError() && query.getItemCount() > 0) {

string ids = "";

for (int i = 0; i < query.getItemCount(); i++) 

ids += ((!string.IsNullOrEmpty(ids)) ? "," : "") + "'" + query.getItemByIndex(i).getID() + "'";

 

this.setProperty("project", ids);

this.setPropertyCondition("project","in");

}

 

return this;



handpuppet - Monday, July 20, 2015 1:39 PM:

Thank you very much, Zahar!  I have a working solution now.