Unable to save document obtained from DocumentContext

I have written an agent which gets invoked from web action as follows:@Command([ToolsRunMacro] ; “AddActivityForToday” )

The agent code is as follows:

Dim session As New NotesSession

Dim currDoc As NotesDocument

Set currDoc = session.DocumentContext

Call currDoc.save(True,False)

While debugging the above agent I found that currDoc doesn’t get NotesId after the save call. Because of which my following code fails with error ‘Invalid or Nonexistent document’:

Dim db As NotesDatabase

Set db = session.CurrentDatabase

Set doc = currDoc.copyToDatabase(db)

Any guesses??

Thanks,

Kiran

Subject: Unable to save document obtained from DocumentContext

Why are you not just saving the document?

Subject: RE: Unable to save document obtained from DocumentContext

When the button is pressed, I copy the existing document into another document, leaving the document open for further changes.

Alternatively, I have to save & close the document and compose new document and prefill with values from the previously stored document.

I am not sure if the second approach is possible.

Subject: RE: Unable to save document obtained from DocumentContext

Yes, it is called creating a response document.

Subject: RE: Unable to save document obtained from DocumentContext

It’s not a response. It’s a timesheet application which allows user to add one or more activites per day. Hence all activities are main document. No responses.

Subject: RE: Unable to save document obtained from DocumentContext

I mean to say that it is a response type document (whether or not you formally call it a response ot not).

It sounds as if you are populating a new document with each activity for the day? is that correct? If so, why would you not call it a response document and tie it to the time sheet.

I think more specific from you would be helpful here about what you are trying to accomplish?

Subject: RE: Unable to save document obtained from DocumentContext

I wrote a timesheet application about 6 years back. Now I am trying to get it working over the web.

User can click on ‘Add Activity’ button to create a new activity for today. The activity could be for (1.00 or 0.75 or 0.50 or 0.25) day. If user chooses anything but 1.00, he can add another activity for the same day, which is ‘Add activity for today’. In that case, I need to copy the customer, project, subsystem, etc into new document. The user would update the description and some other fields and will click save and close or repeat above steps to complete the day.

Hence the need to save the current document and open a new document with some pre-filled fields.

Any solution?

Subject: RE: Unable to save document obtained from DocumentContext

If you open the form withnthe Query_String Parameter of “parentUnid=<parentdocunidstring”, the vlues should inherit no problem.

I would still argie that each activity, if tracked as a separate document, should be treated as a response to the timesheet because it is PART of that timesheet. It can then be displayed in an embedded view.

Subject: RE: Unable to save document obtained from DocumentContext

Thanks for help. I am still using main document instead of response document. But I got it working now. Here is how.

Instead of using doc.copyToDatabase(db), I use

Dim newDoc As NotesDocument

Set newDoc = new NotesDocument(db)

Call doc.copyAllItems(newDoc)

-Kiran

Subject: Unable to save document obtained from DocumentContext

The DocumentContext for a web agent is the HTTP Request to run the agent itself. It’s more-or-less a collection of CGI variables – and it has nothing whatever to do with the document that was in the browser when the action button was clicked.

Subject: RE: Unable to save document obtained from DocumentContext

Then how can I save the currently open document when a button is pressed and execute remaining code?

Subject: RE: Unable to save document obtained from DocumentContext

Save the document via a normal submit button (@Command([FileSave]);@Command([FileCloseWindow])), and use a the WebQuerySave event to run any additional code. Note: do NOT call a save on the current document (which in a WQS is DocumentContext) in your WQS agent – that will cause problems with attachments, rich text fields, etc.

Subject: RE: Unable to save document obtained from DocumentContext

I would like to keep the document open for further editing after it is being saved. How can I achieve it? Thanks

Subject: RE: Unable to save document obtained from DocumentContext

Same deal, but use @Command([FileSave]) ONLY in the save button. Again, let the document save itself – you can change field values in the WQS agent, but don’t call a save 'cos one’s going to hapen anyway.

Subject: RE: Unable to save document obtained from DocumentContext

Thanks for help. I found some wierd behaviour though. The following formula won’t take me to the page specified by $$Return field.

@If(@Command([FileSave]);@Do(@Command([ToolsRunMacro] ; “RepeatActivityForMonth” );@Command([FileCloseWindow]));“”)

I had to add @Command([FileSave]); before @Command([FileCloseWindow]) to get it working !!!

Subject: RE: Unable to save document obtained from DocumentContext

Why is there an @If in there? That’s great for the Notes client, but it won’t work on the web. Your save&continue button should be @Command([FileSave]), and your save&close should be:

@Command([FileSave]);

@Command([FileCloseWindow")

Your agent should be run from the WebQuerySave event of the form, NOT from your buttons.