Ronan - Thursday, October 14, 2010 1:28 PM:
Hello,
Consider the following client JavaScript snippet (using Innovator 9.2 DFMEA model from QP):
var inn = this.newInnovator();
var itm0 = this.newItem("DFMEA", "get");
var itm1 = this.newItem("DFMEA DFMEA Item", "get");
var itm2 = this.newItem("DFMEA Item", "get");
var itm3 = this.newItem("DFMEA Item DFMEA Function", "get");
var itm4 = this.newItem("DFMEA Function", "get");
itm3.setRelatedItem(itm4);
itm2.addRelationship(itm3);
itm1.setRelatedItem(itm2);
itm0.addRelationship(itm1);
var res = itm0.apply();
var dff = res.getItemsByXPath("//Item[@type='DFMEA Function']").getItemByIndex(0);
debugger;
When debugging under Visual Studio 2008,
- res.ToString (correctly) returns the whole tree.
- dff.ToString (incorrectly) returns the same whole tree, instead of extracting just the requested part. Note that node.xml is correct.
Sometimes it happens, sometimes not, and I've been unable to determine the conditions leading to this behavior. Has anybody encountered this? Is this an Aras/JScript/VS bug? Any known workaround?
Not that I use ToString() in my methods, but being able to quickly peek at it is appreciable during debugging sessions.
Brian - Tuesday, October 19, 2010 8:18 AM:
Hi Ronan,
I can't explain it but I have seen the same thing. The getItemsByXPath does return the whole string if you have a look at the returned item BUT it still gives you access to the individual/group of items identified by the XPath statement. I agree that it is frustrating when you can't easily see that the getItemsByXPath has found what you expect just be looking at it.
You say this happens sometimes and sometimes not. In my experience it always returns the whole tree but still knows where in the tree it is actually pointing to.
Cheers,
Brian.
vishal_trivedi - Monday, November 29, 2010 7:19 AM:
Hi Ronan,
If you are fetching an Item with it's relationship :-->
it will return all heirarchy better if you go with Relationship Item type.
E.g. If there is an Item type called "Project" and related with "Part" so, if u want find data by relationship but want to fetch the data from either source or related item.
Just refer below example. If I am not wrong or If i have understood your problem then below solution will work for you.
Innovator inn = this.getInnovator();
//Get all available parts...
Item allPart = this.newItem();
allPart.loadAML("<Item type='Project Part' action='get' select='source_id(*),related_id(*)'></Item>");
Item resPart = this.newItem();
resPart = allPart.apply();
string resultStr = ""; // This string will just collect the result it is upto you how do u want to use?
for
(int partCnt = 0;partCnt<resPart.getItemCount();partCnt++)
{
//Fetching data of source(From side) i.e. Project...
Item resByXpath = this.newItem();
resByXpath = resPart.getItemByIndex(partCnt);
resByXpath = resByXpath.getItemsByXPath("source_id/Item[@type='Project']");
resultStr = resByXpath.getProperty("PROPERTY_NAME");
}
-- Vishal
Ronan - Tuesday, October 19, 2010 8:53 AM:
Hello Brian,
Yup I confirm I have the exact same behavior. Now I feel less alone :P , let's hope this gets fixed someday...
Good day,
Ronan
aknourenko - Thursday, October 28, 2010 3:28 PM:
The Aras.IOM.Item.ToString() is currently returns outer XML of the whole XML document. Because your "diff" item obtained by getItemByXPath(...).getItemByIndex(0) has the same owner document as "res" item (in other words: in both items property "dom" references the same object; see the documentation for getItemByIndex(..) and getItemByXPath(...) which explicitly mentions this) the result of ToString() for both of them is the same. Note that property "node" on these items point to a different places in the XML document; in other words - each item knows which part of the overall XML document it represents. The bigger question though is why do you need a string representation of these items? Just for debugging? In general, if you use IOM you never need to get the string representation of an item.
Ronan - Thursday, October 28, 2010 3:46 PM:
Hi,
Yes it is just for debugging (as mentioned in my first post, "Not that I use ToString() in my methods, but being able to quickly peek at it is appreciable during debugging sessions."). I used to look at it (and not node.xml) because it is the first thing you stumble upon when opening a watched Item, but now that I know that I'll look at node.xml.
Thanks for the answer and the pointer to the documentation!