Solved

Import Response Documents

Posted on 2011-09-09
29
403 Views
Last Modified: 2013-12-18
Can anyone explain to me how to import response documents?

I have a document that has company profiles in it and each company can have various contacts. I created a Contact form with the companies and then a Contact form that is a response form to the Company form.  I have imported the companies but now when I try to import the contacts they are coming in as main documents and not a response back to the company? I have been reading the forums and searching the web and still have not found an answer that is helpful.

Thank you so much for any assistance!
0
Comment
Question by:kali958
  • 15
  • 12
  • +1
29 Comments
 
LVL 7

Expert Comment

by:Sam654
ID: 36515427
It's because they don't have an association with the parent document. They need a $Ref field with the company profiles UNID in.
You're going to need to write an agent to associate them!
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36515872
Agree. The response documents don't have a parent, in Notes vocabulary they are orphans if you don't do anything about it. Write an agent that selects the responses, finds the Company and uses MakeResponse to link the response to the Company. Suggested name for the agent: Adopt orphans.

You may also need a second agent, one that picks up orphans and reunites them with the parent document. You know users: Ctrl-X removes a document, Ctrl-V pasts it back again, but maybe not in the correct position. When using a document hierarchy, you have to take care of these kinds of trouble.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36521050
My other suggestion.... as useful as they can be in some circumstances, with users using them their correct operation can be difficult to explain...  so maybe don't use response documents is another option.

Instead record the company UNID in a field on the Contact document.  Record the company document's UNID in a CompanyID field on it's own doc. too.

Then you can show them in a view by using the company name field you have inherited under the contact etc. and have an embedded view in the company showing contacts etc. using single category view based in the company UNID field if you wish.

And to deal with a user who has copy/pasted or similar the "parent" company document could have a scheduled agent which looks for company documents where the real UNID doesn't match the one in the company ID field and then can go off and find any contacts that were related to the "old" company ID and change their fields.

Overall not a huge amount different to using response and the ideas by Sjef but by using a different field to store the UNID to link rather than the built in response relationship it is easier to survive users!

Hmm, sounded so simple in my head, clear as mud having written it down!

Steve
0
 

Author Comment

by:kali958
ID: 36522237
I do the $Ref field on the Contact Form.  I also have a field MainID on the company form with the UNID and a field on the Contact form that inherits from the Company.   I did find that in the books/internet searches.  I do totally get that with out the tie to each other, the response doc will be come a orphan.

Here is the thing, I have no idea how to write the agent that would look up the correct $Ref/UNID for the contact form.  Can I use @Formula or does it need to be scripted?  I would need some help in writing the agent of directly. I get the logistics of how it would work but as for writing it would be a different story.

Any help would be greatly appreciated - Thanks for the answer so far, always so helpful
0
 

Author Comment

by:kali958
ID: 36522308
BTW - this is only a one time function of importing the company/contacts.  Once imported it will be updated going forward manually.  Does that make sense?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36522342
To programmatically attach a response to a main document you really have to use script. The parent should have some key that allows you to find it using a view and the key (using GetDocumentByKey)

As for your BTW: yep makes sense, but don't forget you need some sort of repair agent, i.e. an agent that repairs the main-response document hierarchy when something goes wrong (which it usually does).
0
 

Author Comment

by:kali958
ID: 36522351
Okay, so let me walk thru this:

I have imported all the companies and they have a UNID on them.

I can import the response documents but when I do, they will not have a tag back to the company that they are the contact for.

So I need to create a script that would look at what the company name is on the response document and then to and look up that company name and find the UNID on the form and then bring it back and set the MainID field on the response document?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36522445
Yes, about 95% correct, except for the part where you link the response to the main document: you *must* use MakeResponse to get a real parent-child relationship. You can set other fields as well, but then it won't result in a hierarchy.
0
 

Author Comment

by:kali958
ID: 36522527
Do I need to still makereponse if I do the import and use the "Response Document" in the file import window?
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36522549
Aaah, that I don't know. It might be a very good option for you to try that indeed. I never did use the automated child import stuff (human trafficking is illegal in most countries anyway... ;-))
0
 

Author Comment

by:kali958
ID: 36522559
Okay - here is what I have written. Trust me this is a shot in the dark and I am trying to figure this out - What do you think Sjef, am I even close?

Sub Initialize()
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument

Set session = New NotesSession
Set db = session.Currentdatabase
Set view = db.GetView("Contact")
Set doc = view.GetFirstDocument

' Can I now go and look up the Company Name and find the UNID here?

Dim dbCompany As NotesDatabase
Dim viewCompany As NotesView
Dim docCompany As NotesDocument

Set viewCompany = db.getView("vUNID")

Do While Not doc Is Nothing
      Set docCompany = viewCompany.GetDocumentbyKey(docCompany.PlanName(0))
      Set doc = viewCompany.getmynextdocument(doc)
      doc.MainID = docCompany.MainID
      Call doc.MakeResponse
      Call doc.Save (True, True)
Loop
      
End Sub
0
 

Author Comment

by:kali958
ID: 36522578
LOL...at least I can laugh during this learning process!

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36522674
:-))

1/ The key in the company view should correspond to the first sorted column of the view (PlanName) and not to the UNID (I guess that's what you did).

2/ Call doc.MakeResponse(docCompany)

3/ You'd better test the result whether a search resulted in a document
      If Not docCompany Is Nothing Then
0
 

Author Comment

by:kali958
ID: 36522737
I have no idea why I am not getting this - I mean if I could understand this I think it would also answer my other question I have out there about getting a term date.

1. The Company view have the first column with PlanName (asc/cat) and the second column is the UNID

2. The contact view has the first column with Plan Name (asc) and the second column is the field to import the UNID into from the Company.


How about this:

  Dim workspace As New NotesUIWorkspace
  Dim uidoc As NotesUIDocument    
  Dim Company As String
 
  Dim db As NotesDatabase
  Dim view As NotesView
  Dim doc As NotesDocument

  Set uidoc = workspace.CurrentDocument    
  Company = uidoc.FieldGetText( "PlanName" )

  Set db = New NotesDatabase( "", "" )
  Set view = db.GetView( "Contact" )
  Set doc = view.GetDocumentByKey( Company )
  Call uidoc.FieldSetText _
  ( "MainID", doc.MainID( 0 ) )
  Call doc.MakeResponse(doc.Company)
  Call doc.Save (True, True)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:kali958
ID: 36524825
Tried a different version - someone else said that since I am importing the data as a reponse doc that I do not need the MakeResponse - so I have this now:

Thoughts, change, suggested other employement since I dont get this....

Sub Initialize()
Dim Session As NotesSession
Dim Db As NotesDatabase
Dim View As NotesView
Dim Doc As NotesDocument
Dim key As String

Set Session = New NotesSession
Set Db = Session.CurrentDatabase
Set view = Db.GetView("Advisor") 'This is the view that has my docs in I want to update
Set doc = view.GetFirstDocument
key = doc.PlanName(0)

Dim DbOther As NotesDatabase
Dim ViewOther As NotesView
Dim docOther As NotesDocument
Set ViewOther = db.getView("Company")

Do While Not doc Is Nothing
      Set docOther = view.GetDocumentByKey( key )
      doc.MainID = docOther.MainID(0)
      Loop
0
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 500 total points
ID: 36526237
Sub Initialize()
Dim Session As New NotesSession
Dim Db As NotesDatabase
Dim View As NotesView
Dim Doc As NotesDocument
Dim nextDoc As NotesDocument
Dim key As String

Set Db = Session.CurrentDatabase
Set view = Db.GetView("Advisor") 'This is the view that has my docs in I want to update
Set doc = view.GetFirstDocument

Dim DbOther As NotesDatabase
Dim ViewOther As NotesView
Dim docOther As NotesDocument
Set ViewOther = db.getView("Company")

Do While Not doc Is Nothing
      Set nextDoc= view.GetNextDocument(doc)
      key = doc.PlanName(0)
      Set docOther = view.GetDocumentByKey( key )
      If Not docOther Is Nothing Then
            doc.MainID = docOther.MainID(0)
            Call doc.makeResponse(docOther)
      End If
      Set doc= nextDoc
Loop

If the import does what I think it does, I suppose you need to have one file with ONLY response documents.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36526347
Ah, wait... The last few lines should at least read:

      If Not docOther Is Nothing Then
            doc.MainID = docOther.MainID(0)
            Call doc.makeResponse(docOther)
            Call doc.Save(True, False)
      End If
      Set doc= nextDoc
Loop
0
 

Author Comment

by:kali958
ID: 36528966
That is what I have, two imports.  Once is the company and the other is the contacts with the first column being the company name.

Okay So let me see if I understand what you wrote.

The beginning part is the declarations

The getview "Advisor", this is the view I want to update the documents in

Then going to the viewother "Company" - this is the view I want to get data from

Then the part you wrote says - go to the next doc, and the key is going to be PlanName in the Company View.  Then I want the field MainID on the main document in the Advisor view to be the same as the MainID from the Company view? and then making the document a response?

Am I at least understanding how this works?  It would be helpful to make sure i get it. I have another database that it would be helpful to use this code to update with term dates from a library database. OH to early to think about that...



0
 

Author Comment

by:kali958
ID: 36529249
I ran the code this morning and it was not working. So I added a msg box to display the docOther.MainID(0) and it is look at at the advisor view to pull that value, not the Company view which has the UNID in the MainID field.

I wrote this to see if I could display the mainID from the company form and this worked

Sub Initialize ()
      Dim session As New NotesSession
      Dim db As NotesDatabase
      Dim view As NotesView
      Dim doc As NotesDocument
      Dim nextdoc As NotesDocument
      Dim key As Variant
      
      Set db = session.CurrentDatabase
      Set view = db.getview("Company")
      Set doc = view.GetFirstDocument
      
      Do While Not doc Is Nothing
      Set nextdoc = view.GetNextDocument(doc)
      key = doc.MainID(0)
      MsgBox key
      Set doc = nextdoc
      Loop
      
Now i am just trying to figure out how to put them together.
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 500 total points
ID: 36529316
Ah... Of course.

Do While Not doc Is Nothing
      Set nextDoc= view.GetNextDocument(doc)
      key = doc.PlanName(0)
      Set docOther = viewOther.GetDocumentByKey( key )
      If Not docOther Is Nothing Then
            doc.MainID = docOther.MainID(0)
            Call doc.makeResponse(docOther)
            Call doc.Save(True, False)
      End If
      Set doc= nextDoc
Loop
0
 

Author Comment

by:kali958
ID: 36529427
Well it runs with no errors but when I did the debugger it is getting to If Not docOther is nothing and then skipping the three lines and looping back.

Then I was getting object variable not set on the doc.MainID = docOther.MainID(0)
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36529596
Did you see the difference with your code? Only 5 letters... ;-)
0
 

Author Comment

by:kali958
ID: 36529612
No, i dont see the difference....adding the end if before the loop?

Serious banging of head on desk at this point. I get it to run w/o errors but not updating.  Call Save, Call Refresh???
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36529650
You were searching the wrong view.

      Set docOther = viewOther.GetDocumentByKey( key )

Now it searches the companies view.
0
 

Author Comment

by:kali958
ID: 36529673
seriously...............

ugh
0
 

Author Comment

by:kali958
ID: 36529701
when I run all the codes, I still get a object variable not set on the

doc.MainID = docOther.MainID(0)

I dont get it , I mean the doc = Notes Document and docOther = notes document so they have been declared.
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36532708
What's the current code?
And do you use the debugger to test-drive your code?
You could also add error trapping code:
- at the start, add a line with
      On Error Goto oops
- just before the End Sub, add
exitsub:
      Exit Sub
oops:
      Error Err, Error$ & " on line " & Erl

You might even consider more and better error handling code, as described here:
http://www.ferdychristant.com/blog//articles/DOMM-6BPT8R

And, declared or not, the message is: you use an empty object variable, i.e. one not initialized with an object. Ut could be DbOther for example, if it's still there.
0
 

Author Comment

by:kali958
ID: 36536045
I really really hate to say this - but it was the data

The documents were not importing correctly but, I fixed that this morning and ....

IT WORKED...IT WORKED IT WORKED IT WORKED (Yes, I did a dance in the aisle and my cube mates think I am nuts).  Thank you thank you

As usual, Sjef, you have saved me.  I always learn so much from you. I am going to go back now and do the Error Trap and learn more about that!
Do While Not doc Is Nothing
      Set nextDoc= view.GetNextDocument(doc)
      key = doc.PlanName(0)
      Set docOther = viewOther.GetDocumentByKey( key )
      If Not docOther Is Nothing Then
            doc.MainID = docOther.MainID
            Call doc.makeResponse(docOther)
            Call doc.Save(True, False)
      End If
      Set doc= nextDoc

Open in new window

0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 36536493
W O N D E R F U L !!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
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
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
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…

758 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

20 Experts available now in Live!

Get 1:1 Help Now