tbischel - Tuesday, January 19, 2010 8:25 PM:
I am trying to build custom tables to be displayed in SharePoint as part of http://plm.codeplex.com/. The default SharePoint grids seem to be set up to display all items of a particular type, but what I would like to do is display all items of a particular type constrained by a given relationship, and I am somewhat confused how do do this in AML
so I have itemtypes foo and bar, as well as relationship foobar. Foo has a property x that I want to set, and bar has property y that I want to display in my table.
<AML>
<Item type="foo" action="get">
<x>Constraint</x>
<Relationships>
<Item type="foobar" select="related_id(y)"></item>
</Relationships>
</Item>
</AML>
When I do this, the column for the y property turns up blank. Any suggestions?
RobMcAveney - Wednesday, January 20, 2010 12:12 PM:
The SharePoint Grid was only built to handle a single ItemType. The best solution would be to modify the web part to handle relationships, etc., but there are a couple techniques you could use to get the results you're looking for without changing the web part. Whichever technique you use, make sure to account for multiple "foobar" relationships on the same "foo" item (unless you have it constrained to only one, that is).
The easiest way is to take advantage of the fact that the property values are being read via an XPath. In your case you'd use something like this in the Property field for the SharePoint Grid Column: Relationships/Item[@type='foobar']/related_id/Item[@type='bar']/y. Unfortunately, that field is limited to 32 characters so you either have to expand the length of the property or shorten the XPath to something like: .//Item[@type='bar']/y. This approach should get the field populated, but search will probably not work correctly.
The other approach would be to use server events to make "y" appear to be a property of "foo" instead of "bar". Change the query to:
<Item type="foo" action="get">
<x>Constraint</x>
<Relationships>
<Item type="foobar" action="get" select="related_id">
<related_id>
<Item type="bar" action="get" select="y">
</Item>
</related_id>
</Item>
</Relationships>
</Item>
Then use code something like this OnAfterGet on "foo":
for (int i=0; i<this.getItemCount(); i++)
{
Item fooItem = this.getItemByIndex(i);
Item barItem = fooItem.getItemsByXPath("Relationships/Item[@type='foobar']/related_id/Item[@type='bar']");
if (barItem.getItemCount() > 0)
{
fooItem.setProperty("y",barItem.getItemByIndex(0).getProperty("y",""));
}
}
return this;
Again, this should get the field populated, but search will not work on the "y" property. To get search working you'll need to translate criteria on the "y" property on "foo" to criteria on "bar". To do that, use something like this OnBeforeGet on "foo":
string yCriteria = this.getProperty("y","");
if (yCriteria.Length > 0)
{
Item barItem = this.getItemsByXPath("Relationships/Item[@type='foobar']/related_id/Item[@type='bar']");
if (barItem.getItemCount() == 1)
{
barItem.setProperty("y",yCriteria);
barItem.setPropertyAttribute("y","condition",this.getPropertyAttribute("t","condition"));
}
}
return this;
I haven't tested any of this code, but hopefully you get the idea. I have done similar things in the past, so I'm pretty sure it will work. Let me know if you have questions.
Rob
tbischel - Thursday, January 21, 2010 6:17 PM:
Thanks for the suggestions. I ended up modifying the webpart to allow relationships to be used for filtering, as you first suggested.
I'm running into another problem, maybe you have an idea what is going on. My tables appear on the SharePoint grid just fine, but when I click on the link to drill down, I get a SOAP error that says ..."<af:legacy_detail>The Database is not available.</af:legacy_detail>"... This happens both for the original webpart as well as my modified version, and is somewhat baffling since it is able to grab things from the database to display on the table. The link appears to be something like:
192.168.2.5/.../item_opener.htm
Is there specific setup process to get an item opener page to work?