4

I'm trying to change class for a given document and below is the code that I used

Document p8Document = Factory.Document.getInstance(p8ObjectStore,
                oldDocumentClassName, new Id(documentId));
p8Document.changeClass(newDocClassName);
        p8Document.save(RefreshMode.REFRESH);

Upon executing the code, I can see that document class is being changed successfully. Now the problem is if I run the code again for the same guid, the below line fetches the document again with the old document class name.

Document p8Document = Factory.Document.getInstance(p8ObjectStore,
                    oldDocumentClassName, new Id(documentId));
bajji
  • 1,271
  • 3
  • 15
  • 37

1 Answers1

5

By using getInstance, you are not asking the server to verify the existence of the object. Use fetchInstance instead.

From Instantiating Objects

The getInstance methods are used to instantiate an object that references a server object that is assumed to already exist. The existence of the object is not verified on the Content Engine server, and no round trip to the server is made until you perform a function on the object

getInstance is a way that you can setup an object while avoiding a trip to the CE server.

The fetchInstance methods instantiate an object by first making a round-trip to the Content Engine server and retrieving ("fetching") property values.

fetchInstance actually will retrieve the object from the CE server.

  • Well, let me try that. The code snippet from IBM uses getInstance so I went with that – bajji Oct 12 '17 at 20:10
  • 1
    There is nothing wrong with your first two lines of code. It's the 3rd line that has a bad assumption. – Christopher Powell Oct 13 '17 at 03:12
  • @ManjunathaMuniyappa do you have the URL for the code snippet from IBM? I might be able to explain why they used getInstance. – Christopher Powell Oct 17 '17 at 14:34
  • here you go Sir, https://www.ibm.com/support/knowledgecenter/en/SSNW2F_5.2.0/com.ibm.p8.ce.dev.ce.doc/document_procedures.htm look for the line doc.changeClass(“newDocClass”); – bajji Oct 17 '17 at 18:54
  • Thanks. In that example, IBM is showing you how to change the class, but never references any of the properties of the document. Because there isn't any need to know the current properties of the document, the getInstance method is called in order to save time. When the Save method is called, the server will validate the existence of the document, and throw an exception if the document is not found (I believe that is an Object_Not_Found exception). If they had needed to validate a property before changing the class, a fetchInstance on either the document, or the property would need to occur. – Christopher Powell Oct 18 '17 at 12:15
  • @ManjunathaMuniyappa Did this solve your problem? If not, could you please extend on the question? – Christopher Powell Oct 31 '17 at 15:47
  • @ Christopher Powell, sorry totally forgot to update. I used fetchInstance to change the document class and it;s working.... – bajji Oct 31 '17 at 17:48