?
Solved

Change main document into response document

Posted on 2006-05-15
18
Medium Priority
?
463 Views
Last Modified: 2013-12-18
Hello experts,
I am using the code below in an agent which I call from a button in a view after selecting a document to check and see if there are existing documents with the same lot number. If it exists it asks if I wish to switch to the existing document.

My question is this. When I switch to the existing document I want to check if it is already a response document, if it is , then nothing should happen, if it is not then I want to change it into a response to the selected document. How do I do this?


Check for duplicate lot code:

Dim workspace As New NotesUIWorkspace
      Dim uidoc As NotesUIDocument
      Dim doc As NotesDocument
      Dim curdoc As NotesDocument
      Dim db As NotesDatabase
      Dim view As NotesView          
      Dim PartNo As String
      Dim answer As Integer
      Dim codeType As String
      Set uidoc = workspace.CurrentDocument
      If uidoc.IsNewDoc Then
            Set curdoc = uidoc.Document
            Set db = curdoc.ParentDatabase
            Set view = db.GetView("BatchStatusLot")'All Fields Values sorted
            PartNo = uidoc.FieldGetText("batch") 'The FieldName you want to check
            Set doc = view.GetDocumentByKey(PartNo)
            If Not (doc Is Nothing) Then
                  Forall i In doc.Items
                        If (i.Text = PartNo) Then codeType = i.Name
                  End Forall
                  answer = Messagebox( "Duplicate " & codeType & " found. Click Ok to switch to existing document.", 1+32, "Duplicate Lot Number")
                  If (answer = 1) Then
                        curDoc.SaveOptions = "0"
                        Call uidoc.Close          
                        Delete uidoc
                        Call workspace.EditDocument(True, doc)
                  End If
            End If  
      End If      
0
Comment
Question by:schmad01
  • 5
  • 5
  • 4
  • +1
16 Comments
 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 16685221
Use MakeResponse Method of the NotesDocument

~Hemanth
0
 
LVL 15

Expert Comment

by:mshogren
ID: 16685258
Try adding the few lines as below:

Dim workspace As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Dim doc As NotesDocument
     Dim curdoc As NotesDocument
     Dim db As NotesDatabase
     Dim view As NotesView          
     Dim PartNo As String
     Dim answer As Integer
     Dim codeType As String
     Set uidoc = workspace.CurrentDocument
     If uidoc.IsNewDoc Then
          Set curdoc = uidoc.Document
          Set db = curdoc.ParentDatabase
          Set view = db.GetView("BatchStatusLot")'All Fields Values sorted
          PartNo = uidoc.FieldGetText("batch") 'The FieldName you want to check
          Set doc = view.GetDocumentByKey(PartNo)
          If Not (doc Is Nothing) Then
               Forall i In doc.Items
                    If (i.Text = PartNo) Then codeType = i.Name
               End Forall
               answer = Messagebox( "Duplicate " & codeType & " found. Click Ok to switch to existing document.", 1+32, "Duplicate Lot Number")
               If (answer = 1) Then
                    if not(doc.IsResponse) then
                        doc.makeresponse(curDoc)
                        doc.save true, true
                    end if
                    curDoc.SaveOptions = "0"
                    Call uidoc.Close          
                    Delete uidoc
                    Call workspace.EditDocument(True, doc)
               End If
          End If  
     End If
0
 

Author Comment

by:schmad01
ID: 16685347
Getting Illegal pass by value (curDoc)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 24

Expert Comment

by:HemanthaKumar
ID: 16685414
use call doc.makeresponse(curdoc)
0
 
LVL 15

Expert Comment

by:mshogren
ID: 16685703
Sorry, I didn't check carefully but that is just a syntax error.  Either HemanthaKumar's
Call doc.makereponse(curdoc)
or
doc.makeresponse curdoc
will work
0
 

Author Comment

by:schmad01
ID: 16685729
Variant does not contain an object.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16692148
If uidoc.IsNewDoc Then  << I think you have to save the uidoc before you can make another a response to it.
0
 
LVL 15

Expert Comment

by:mshogren
ID: 16692602
That raises an interesting question.  The code is preventing this new document from being saved ever, so there should be no need to make it a response to another document.

Perhaps we need to clarify the logic of what you wish to do...
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16695646
Yup, it can't be a response to a non-existant document, you'll have orphans.   You have to save the open document before you continue, or if they don't save, then exit the sub.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16719504
How are we doing on this?  Do you know how to resolve the problem, or do you require more assistance?
0
 

Author Comment

by:schmad01
ID: 16798081
Sorry, got pulled away for something else. Will get back into this today and clarify.  Thanks.
0
 

Author Comment

by:schmad01
ID: 16800824
Ok, will try to clarify.  I have a saved document open (Yieldsheet1 form). I click a button to created a response document (scanform form) and it inherits certain fields from Yieldsheet1 document. The scenario that may arise is that there may already be a scanform created from the past. The code searches by ipl code. If it finds one of these documents , I switch to it. The problem is that it is a main document and I want to convert it into a response document to the already opened Yieldsheet1 document.  Is that any clearer?  Sometimes what is in my mind doesn't make it to the keyboard very well. Let me know if any more questions.
0
 
LVL 18

Expert Comment

by:marilyng
ID: 16803687
I think where we left off was that your open document might be a new document, then you can't make the next document a response to the open one until you save the open document.
0
 

Author Comment

by:schmad01
ID: 16851804
My open document is a saved document, not a new one.
0
 
LVL 15

Accepted Solution

by:
mshogren earned 500 total points
ID: 16853010
The code only executes inside this if statement:

 If uidoc.IsNewDoc Then

That is, it only executes if the current doc is a new one.

I think I see now what is going on.  Some where in your code above we need to get a reference to the parent document


Dim workspace As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Dim doc As NotesDocument
     Dim curdoc As NotesDocument
     Dim parentdoc as NotesDocument
     Dim db As NotesDatabase
     Dim view As NotesView          
     Dim PartNo As String
     Dim answer As Integer
     Dim codeType As String
     Set uidoc = workspace.CurrentDocument
     If uidoc.IsNewDoc Then
          Set curdoc = uidoc.Document
          Set db = curdoc.ParentDatabase
          Set parentdoc = db.GetDocumentByUNID(curdoc.ParentDocumentUNID)
          Set view = db.GetView("BatchStatusLot")'All Fields Values sorted
          PartNo = uidoc.FieldGetText("batch") 'The FieldName you want to check
          Set doc = view.GetDocumentByKey(PartNo)
          If Not (doc Is Nothing) Then
               Forall i In doc.Items
                    If (i.Text = PartNo) Then codeType = i.Name
               End Forall
               answer = Messagebox( "Duplicate " & codeType & " found. Click Ok to switch to existing document.", 1+32, "Duplicate Lot Number")
               If (answer = 1) Then
                    if not(doc.IsResponse) then
                        doc.makeresponse(parentdoc)
                        doc.save true, true
                    end if
                    curDoc.SaveOptions = "0"
                    Call uidoc.Close          
                    Delete uidoc
                    Call workspace.EditDocument(True, doc)
               End If
          End If  
     End If
0
 
LVL 18

Assisted Solution

by:marilyng
marilyng earned 500 total points
ID: 16876983
if it is not then I want to change it into a response to the selected document<<

Ah, then you would need to add another lookup once you have the handle on the new document.

So the flow is:

User opens a new document.
    Fills in some information
    Somewhere before the save, the agent kicks in and checks to see if this new document is a duplicate.
       if  YES - then ask to open the original
                  if YES - then while you have a handle on the original, check to see if THAT document is a response.
                       IF NO- then do a lookup to find the parent document, and before the user opens it, make it a response.
                           save the document
                           open the document and exit the code.
                       IF YES - Open the other document and discard the NEW document.
       If NO - (Use doesn't want to open the duplicate) - abyss.. ? AArrrgh. No trap or code here.

So you're going to need a function to find the Parent document as mshogren says.

Do you need further assistance to create the code?  Or will the logic suffice?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Loops Section Overview
Suggested Courses

809 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