Sebastian Uecker - Wednesday, May 14, 2014 5:25 AM:
Hi there,
I am trying to get the names of file properties on a specific ItemType. The FileTestType1 has two properties (_attachement_1, attachement_2) with data_type = Item and data_source = File. I wrote this external C#-method:
List<String> results = new List<String>();
String itemType = "FileTestType1";
Item itm = inn.newItem("ItemType", "get");
itm.setProperty("name", itemType);
itm = itm.apply();
itm.fetchRelationships("Property");
Item relationships = itm.getRelationships("Property");
int count = relationships.getItemCount();
for (int i = 0; i < count; i++) {
Item prop = relationships.getItemByIndex(i);
if (prop.getProperty("data_type") == "Item" && prop.getPropertyItem("data_source").getProperty("name") == "File"){
results.Add(prop.getProperty("name"));
}
}
Unfortunately the results-List stays empty. When I debug the thing it looks like the prop-Item is assigned the sourceItem instead of the RelationshipItem, so there are no data_type or data_source properties on it.
getRelatedItem won't do since the "Property" Relation of "ItemType" is a NoRelated, data_type and data_source hence stickng directly on the Relationship-ItemType.
What is the correct way to get to access the Property-Relationship-Items or is there another way to get to an ItemType's properties' metadata?
Best regards, Sebastian
Sebastian Uecker - Wednesday, May 14, 2014 6:59 AM:
In the meantime I was able to solve half of the problem noticing that "data_type"-property values are returned lower case ("item") and I compared to uppercase ("Item").
Yet the second half of the problem remains: Even though prop.getProperty("data_source") delivers the correct ID of the ItemType (i.e. of "File" or "Identity") I just get empty strings when trying to get any properties off the propertyItem...
gks - Wednesday, May 14, 2014 8:07 AM:
You get empty strings because you have to make another call to the server with the ID.
Use the .ToString() method of the Item class to see what data is actually available.
the data_source tag should look like this:
<data_source keyed_name=... type=...>id</data_source>
however .getProperty does not make servercalls and thus you get null strings.
you have to make another server call with inn.getItemById(type, id) or inn.applyAML(...) etc. Depending on what you like most.