jacobandrews - Monday, August 26, 2013 5:06 AM:
ERROR while trying to execute the statement to create iDownload_file, the array goes out of bound... the count is 0..
I am not able to traverse the relationship between the Part Document and file ... Please have a look at the code below and give me a suggestion of where i could be wrong..
I want to download the text file that is attached to the document.
public int Export_File(Innovator MyInnovator, string sPart_num, String sRevision_num, string sPath)
{
//Check if the Part Item exists
Item iQryItem = MyInnovator.newItem("Part", "get");
iQryItem.setAttribute("select", "item_number");
iQryItem.setProperty("item_number", sPart_num);
iQryItem.setPropertyCondition("item_number", "eq");
iQryItem.setProperty("major_rev",sRevision_num);
iQryItem.setPropertyCondition("major_rev", "eq");
Item iResults = iQryItem.apply();
int nCount = iResults.getItemCount();
if (nCount == 1)
{
Item iPart_doc = iResults.fetchRelationships("Part Document").getRelationships("Part Document").getItemByIndex(0);
Item iRes_doc = iPart_doc.apply();
string id1 = iPart_doc.getID();
iRes_doc.lockItem();
Item iDownload_file = iRes_doc.fetchRelationships("Document File").getRelationships("Document File").getItemByIndex(0);
Item iRes_file = iDownload_file.apply();
string id2 = iRes_file.getID();
int lock_status = iRes_file.fetchLockStatus();
if (lock_status == 0)
{
}
else
{
Console.WriteLine("Unable to lock the file
");
}
iPart_doc.unlockItem();
}
else
{
Console.WriteLine("This item not found on the Aras database.
");
return 0;
}
return 1;
}
[email protected] - Monday, August 26, 2013 11:02 AM:
Difficult to see - I think the problem is ...iRes_doc.lockItem().
1) It is not mandatory to lock relations / documents for retrieving files
2) iRes_doc.lockItem() will return a new item - the locked item "iRes_doc = iRes_doc.lockItem();" sould be better
3) Please check number of Items using "getItemCount()" before using "getItemByIndex(0)"
If you have a file - simply use fileItem.checkout().
Additional questions - please let me know.
Jens Rollenmüller, NTT DATA Germany
jacobandrews - Tuesday, August 27, 2013 2:10 AM:
the count is zero...
I am not able to get the Item file of the document
jacobandrews - Tuesday, August 27, 2013 2:12 AM:
I am not able to retrieve the Item "Document File" in the code snippet
[email protected] - Thursday, August 29, 2013 4:38 AM:
I tried it yesterday a little bit more detailed but ran out of time.
Nevertheless I suggest you to redesign the part with the relations. Out of my head it should work like this:
relationItem = myInno.newItem("get","Part Document");
relationItem.setProperty("source_id",part_ID);
Item relatedItems = relationItem.apply();
Item firstRelatedItem=relatedItems.getItemByIndex(0);
Item documentItem=firstRelatedItem.getRelatedItem();
-> same for Document File
Please be aware that you have to check the code above. I haven't tried it! It's only a draft.
Regards, Jens Rollenmüller, NTT DATA Germany