Solved

Create a Response Doc in Lotus Script

Posted on 1998-12-31
11
714 Views
Last Modified: 2013-12-18
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
0
Comment
Question by:deona123198
  • 5
  • 4
  • 2
11 Comments
 
LVL 1

Expert Comment

by:wrichard
ID: 1117832
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...
0
 

Author Comment

by:deona123198
ID: 1117833
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?
0
 

Author Comment

by:deona123198
ID: 1117834
I don't know if the answer is correct, as I get script errors.
Anybody know why?
0
 
LVL 4

Expert Comment

by:stamp
ID: 1117835
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
0
 
LVL 4

Expert Comment

by:stamp
ID: 1117836
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.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:deona123198
ID: 1117837
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?
0
 
LVL 4

Expert Comment

by:stamp
ID: 1117838
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).
0
 

Author Comment

by:deona123198
ID: 1117839
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
0
 
LVL 1

Accepted Solution

by:
wrichard earned 100 total points
ID: 1117840
Since you are using backend classes to create the new document you need to map the fields over that you want to populate in the response doc.  From my first answer the error that you were getting on the line
newdoc = db.createdocument
is because the newdoc needs to be set try this line instead
set newdoc = db.createdocument

then between these 2 lines of code
newdoc.form = "Replacement Sheet"
call newdoc.makeresponse(doc)
map the fileds that you want to inherit values using code similar to this
newdoc.fieldA = doc.fieldA(0)

hope this helps
0
 
LVL 4

Expert Comment

by:stamp
ID: 1117841
After calling "MakeResponse" put this line:
Call W.CurrentDocument.Document.CopyAllItems(newdoc, True )
and assign after this the form item:
newdoc.form = "Replacement Sheet"

0
 

Author Comment

by:deona123198
ID: 1117842
Thanks, problem solved
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This is an old article, please see an updated version of this article, located here: http://www.experts-exchange.com/articles/23619/Notes-8-5x-Windows-7-Notes-info-and-tips.html
This article covers general Notes 8.5 troubleshooting information including recreating the Notes\Data folder.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now