Solved

Create a Response Doc in Lotus Script

Posted on 1998-12-31
11
716 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
msxml3.dll: Not enough storage is available to complete this operation 13 895
Send a link through lotus notes automated mail 11 141
Lotus notes email code 13 94
Lotus notes email code 2 122
Lack of Storage capacity is a common problem that exists in every field of life. Here we are taking the case of Lotus Notes Emails, as we all know that we are totally depend on e-communication i.e. Emails. This article is fully dedicated to resolvin…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

813 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

10 Experts available now in Live!

Get 1:1 Help Now