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
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
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?
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?
ASKER
I don't know if the answer is correct, as I get script errors.
Anybody know why?
Anybody know why?
Try this:
Sub Exiting(Source As Field)
Dim W As New NotesUIWorkspace
Dim session As New NotesSession
If (W.CurrentDocument.FieldGe tText ("Stock") = "Yes") Then
Dim newdoc As New NotesDocument( session.CurrentDatabase )
newdoc.form = "Replacement Sheet"
Call newdoc.makeresponse(W.Curr entDocumen t.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
Sub Exiting(Source As Field)
Dim W As New NotesUIWorkspace
Dim session As New NotesSession
If (W.CurrentDocument.FieldGe
Dim newdoc As New NotesDocument( session.CurrentDatabase )
newdoc.form = "Replacement Sheet"
Call newdoc.makeresponse(W.Curr
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.Curr entDocumen t.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.
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.Curr
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.
ASKER
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?
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).
- "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).
ASKER
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
Should the main doc not be saved before the response is created (to inherrit values)?
If so how?
Regards
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
After calling "MakeResponse" put this line:
Call W.CurrentDocument.Document .CopyAllIt ems(newdoc , True )
and assign after this the form item:
newdoc.form = "Replacement Sheet"
Call W.CurrentDocument.Document
and assign after this the form item:
newdoc.form = "Replacement Sheet"
ASKER
Thanks, problem solved
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...