Link to home
Start Free TrialLog in
Avatar of deona123198
deona123198

asked on

Create a Response Doc in Lotus Script

I have the following code:

Sub Exiting(Source As Field)
     Dim W As New NotesUIWorkspace
     Dim UIDoc As NotesUIDocument
     Set UIDoc = W.CurrentDocument
     If (UIDoc.FieldGetText ("Stock") = "Yes") Then
          Call W.ComposeDocument( "", "", "Replacement Sheet" )
     Else
          Messagebox "You can now click the Save & Close Button.", 0, "Continue"
     End If    
End Sub

This code is executed in the main doc when exiting the Stock field. It is SUPPOSE to compose a response doc (which it doesn't do).  The code works if I create a normal doc with the code instead of a response.  Does anyone know what is wrong and how to fix?  

Greetings
Avatar of wrichard
wrichard

I prefer to use the back end lotusscript classes whenever possible.  The code below is a quick pass at solving your problem.  It will generate a response document for the form you are currently in, save the current form and display the new form to the user.

Sub Exiting(Source As Field)
         Dim W As New NotesUIWorkspace
         Dim UIDoc As NotesUIDocument
         Set UIDoc = W.CurrentDocument
         Dim session as new notessession
         dim db as notesdatabase
         set db = session.currentdatabase
         Dim doc as notes document
         dim newdoc as notesdocument
         If (UIDoc.FieldGetText ("Stock") = "Yes") Then
              newdoc = db.createdocument
              newdoc.form = "Replacement Sheet"
              call newdoc.makeresponse(doc)
              call newdoc.save(true, false)
              set uidoc = w.editdocument(true, newdoc)
         Else
              Messagebox "You can now click the Save & Close Button.", 0, "Continue"
         End If      
    End Sub

Hope this helps...
Avatar of deona123198

ASKER

Sub Exiting(Source As Field)
         Dim W As New NotesUIWorkspace
         Dim UIDoc As NotesUIDocument
         Set UIDoc = W.CurrentDocument
         Dim session as new notessession
         dim db as notesdatabase
         set db = session.currentdatabase
         Dim doc as notesdocument
         dim newdoc as notesdocument
         If (UIDoc.FieldGetText ("Stock") = "Yes") Then
<ERROR IN SCRIPT>  newdoc = db.createdocument          
              newdoc.form = "Replacement Sheet"
              call newdoc.makeresponse(doc)
              call newdoc.save(true, false)
              set uidoc = w.editdocument(true, newdoc)
         Else
              Messagebox "You can now click the Save & Close  Button.", 0, "Continue"
         End If      
    End Sub

I get an error in the script where marked, could anyone please clarify?
I don't know if the answer is correct, as I get script errors.
Anybody know why?
Try this:
Sub Exiting(Source As Field)
     Dim W As New NotesUIWorkspace
     Dim session As New NotesSession
     If (W.CurrentDocument.FieldGetText ("Stock") = "Yes") Then
          Dim newdoc As  New NotesDocument( session.CurrentDatabase )          
          newdoc.form = "Replacement Sheet"
          Call newdoc.makeresponse(W.CurrentDocument.Document)
          Call newdoc.save(True, False)
          Set uidoc = W.EditDocument(True, newdoc)
     Else
          Messagebox "You can now click the Save & Close  Button.", 0, "Continue"
     End If        
End Sub
Sorry. There was still one object not initialized. Try better this:
Sub Exiting(Source As Field)
     Dim W As New NotesUIWorkspace
     Dim UIDoc As NotesUiDocument
     Set UIDoc = W.CurrentDocument
     If (uidoc.FieldGetText ("Stock") = "Yes") Then
          Dim session As New NotesSession
          Dim newdoc As  New NotesDocument( session.CurrentDatabase )          
          newdoc.form = "Replacement Sheet"
          Call newdoc.makeresponse(W.CurrentDocument.Document)
          Call newdoc.save(True, False)
          Set UIDoc = W.EditDocument(True, newdoc)
     Else
          Messagebox "You can now click the Save & Close  Button.", 0, "Continue"
     End If        
End Sub

Remember that your form "Replacement Sheet" has to have "Form type:" set to "Response" to have correct relations.
The Response document is set to response, but none of the fields will inherit the values from the main doc. The response doc is set to formulas inherit values from selected doc.  Otherwise the code looks fine...thanks.
How do I get the formulas to inherit values?
Is this due to the code?
You need two settings:
- "Form type:" set to "Response"
- "Defaults" tab / "On Create:"  set to "Formulas inherit values from selected document"

In the "Default Value" event of every field you want to inherit value from parent set as
formula the name of the field (without quotas).
All settings is as needed, thanks anyway..
Should the main doc not be saved before the response is created (to inherrit values)?  
If so how?

Regards
ASKER CERTIFIED SOLUTION
Avatar of wrichard
wrichard

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
After calling "MakeResponse" put this line:
Call W.CurrentDocument.Document.CopyAllItems(newdoc, True )
and assign after this the form item:
newdoc.form = "Replacement Sheet"

Thanks, problem solved