cancel
Showing results for 
Search instead for 
Did you mean: 

Detaching a document from a Workview Object

Hank_Thomas
Champ on-the-rise
Champ on-the-rise

I am getting an Error when I try to use the DetachDocument method of the WorkviewObject.

Hyland.Unity.Document doc = unityApplication.Core.GetDocumentByID(localDocument.ID );

workviewObject.DetachDocument( doc);

The goal is to modifiy this doc and reindex it and attach the new version to the object.

Any Ideas?

Thanks in advance.

I see the following in the Diag Console:

Object reference not set to an instance of an object.  Hyland.Data.DataOperation Delete 
Hyland.Data.DataOperation Delete
Hyland.Core.Workview.Data.DocumentDataAccess DeleteDocument 
Hyland.Core.Workview.Object DetachDocument 

Hyland.Core.Workview.Services.Unity.WVObject DetachDocument 

1 ACCEPTED ANSWER

Jonathan_Conle1
Star Contributor
Star Contributor

Hello, and thanks for posting to the OnBase Community!

It appears to me that you are retrieving a document by ID, and then detaching that document. This would only work if the document object is the same exact same document object as the document attached to the WorkView object.

The DetachDocument method is specific to removing a document that is already associated.

I would suggest instead to retrieve the document list off of the WorkView object, specify the desired document, detach that document, do your needed task, and then attach the new document.

Here is a similar snippet of what I would suggest:

 

//retrieve the attached documents for a specific object

Hyland.Unity.DocumentList docList = wvObj.Documents;

//qualify the document list to specify the desired document. This example would remove all documents.

foreach(Hyland.Unity.Document doc in docList)

{

args.Object.DetachDocument(doc);

}

//do stuff

//attach the new/modified document

wvObj.AttachDocument(newDocument);

View answer in original post

2 REPLIES 2

Hank_Thomas
Champ on-the-rise
Champ on-the-rise
I can know the document was attached to begin with as that is how I get it to modify and upload it back to onbase all within this same script.

Jonathan_Conle1
Star Contributor
Star Contributor

Hello, and thanks for posting to the OnBase Community!

It appears to me that you are retrieving a document by ID, and then detaching that document. This would only work if the document object is the same exact same document object as the document attached to the WorkView object.

The DetachDocument method is specific to removing a document that is already associated.

I would suggest instead to retrieve the document list off of the WorkView object, specify the desired document, detach that document, do your needed task, and then attach the new document.

Here is a similar snippet of what I would suggest:

 

//retrieve the attached documents for a specific object

Hyland.Unity.DocumentList docList = wvObj.Documents;

//qualify the document list to specify the desired document. This example would remove all documents.

foreach(Hyland.Unity.Document doc in docList)

{

args.Object.DetachDocument(doc);

}

//do stuff

//attach the new/modified document

wvObj.AttachDocument(newDocument);