Solved

Need help creating an Agent to refresh @dblookup fields in all documents using the same form.

Posted on 2008-11-03
3
338 Views
Last Modified: 2013-12-18
Have a small database with Distributor information.  There are 2 forms one for the company and one for the contacts at each company.  Company information is pulled into the Contact form using @dblookup fields.  Problem is when there is a change made on the company form it does not update on the contact form at the same time.  Would like an agent that could do the updates or some other method to keep the information in sync.
0
Comment
Question by:cinamitton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
johnjardin earned 500 total points
ID: 22867185
The best way to do this, is to create a function in a script library, and reference that function in the PostSave Event of your company doc:

So, the PostSave event of your company doc will look like this:

Sub PostSave(Source As Notesuidocument)

        ' Update Contact Docs
        Call UpdateChildDocs( Source )

End Sub


The UpdateChildDocs event will then look something like what I've added in the code snippet area. This will make everything real time. Hope this helps.

John

Sub UpdateChildDocs( uidoc As NotesUIDocument )
	' VARIABLES
	Dim ss As New NotesSession
	Dim db As NotesDatabase
	Dim view As NotesView
	Dim col As NotesDocumentCollection
	Dim companydoc As NotesDocument
	Dim contactdoc As NotesDocument
	Dim key As String
	Dim mustsave As Boolean
	
	' CODE
	Set companydoc = uidoc.Document
	Set db = ss.CurrentDatabase
	Set view = db.GetView( "ViewAliasName" )	' The Alias Name of the View you looking up to 
	
	key = companydoc.LookupKey(0)	' This is the key you were using in the DBLookup
	Set col = view.GetAllDocumentsByKey( key, True )
	Set contactdoc = col.GetFirstDocument
	
	' For Each Doc found in the DB Lookup
	While Not( contactdoc Is Nothing )
		' Reset the Must Save Flag
		mustsave = False
		
		' Check all fields to see if values are the same
		If companydoc.FieldName1(0) <> contactdoc.FieldName1(0) Then
			Call contactdoc.ReplaceItemValue( "FieldName1", companydoc.FieldName1(0) )
			mustsave = True
			
		End If
		
		If companydoc.FieldName2(0) <> contactdoc.FieldName2(0) Then
			Call contactdoc.ReplaceItemValue( "FieldName2", companydoc.FieldName2(0) )
			mustsave = True
			
		End If
		
		' If changes have been made, then Save
		If mustsave Then
			Call contactdoc.Save( True, True )
		End If
		
		Set contactdoc = col.GetNextDocument( contactdoc )
		
	Wend
	
End Sub

Open in new window

0
 

Author Comment

by:cinamitton
ID: 22867297
Thanks for the quick response,  I will test the code to see if it works in our application.
0
 

Author Closing Comment

by:cinamitton
ID: 31512679
Many thanks for the code,

It is working great!!!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

696 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