Post

2 followers Follow
0
Avatar

Save some documents but not others

Hi,

I wrote some code to create a certain document. If the document passes a certain criteria, I want to be able to save that document. If it doesn't, I don't want it to save the document.

Is there a way to do this?

Thanks!

Matthew Shum

Please sign in to leave a comment.

5 comments

0
Avatar

Assuming you are writing a DocumentOperation, I think the nicest way is to throw a DocumentOperationException as soon as you decide not to save the document. Pass a message into the exception explaining why and that will be displayed to the user.

Richard Moir 0 votes
Comment actions Permalink
0
Avatar

That also assumes you are only doing one document. If you have many, then don't add the documents you don't want to save to the list of results that are returned.

Richard Moir 0 votes
Comment actions Permalink
0
Avatar

^ True. Thanks.

I guess my main issue is with saveDocument(). I tried to call it but it won't save the document in question to the folder. So I am not sure if I am using the method correctly.

Matthew Shum 0 votes
Comment actions Permalink
0
Avatar

If you have just created a new document then you shouldn't call saveDocument(). That is only used if you are modifying a document that is already in the database.

To save a new document to the database then you can call DocumentUtilities.addGeneratedDocument

Richard Moir 0 votes
Comment actions Permalink
0
Avatar

Sorry, I want to save an intermediate document to the database. I will try to call DocumentUtilities.addGeneratedDocument. Thanks!

Update: This solved my needs! Thanks!

Matthew Shum 0 votes
Comment actions Permalink