193 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 5
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 6
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 9
3 XPages hints #3: Homepage and Performance improvements
Mon, Feb 29th 2016 5
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 9
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 7
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 9
Top 10
XPages: Handling disabled Checkboxes
Thu, Mar 26th 2015 10
Simple way to make certain elements sticky in your web application (XPages example using OneUI)
Sun, Apr 19th 2015 9
Travelling 2.0: How your smartphone can assist you travelling easier and cheaper
Fri, Jan 15th 2016 9
Creating ICS Calendar Feeds with XPages
Tue, Apr 12th 2016 9
3 XPages hints #2
Wed, Apr 30th 2014 8
Get rid of the agent property “Target documents – all new & modified documents”
Tue, Jan 3rd 2012 7
Leaving the yellow bubble for a while
Sun, Jun 7th 2015 7
Creating a test environment: the easy way
Tue, Jun 3rd 2014 6
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 6
Resolve time difference in hours and minutes of two date/time values
Wed, Aug 17th 2011 5


Creating a test environment: the easy way
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
Frederic dehedin    

Testing without proper data can be quite annoying and sometimes even impossible.

I’m working on an application which consist of more than 5 different NSF files. All data are related to each other and linked with an unique ID. Manually copy / paste all the data is not an option, the chance to forget data and have resulting inconsistencies are too big. Another problem: productive data can grow very big (attachments, rich-text fields and so on), simply copy paste the nsf files may result in using too much disc space in the test environment..

The Solution

So i created a lotusscript agent in order to copy the data of multiple databases:

  1. loops through a list of source / target database paths
  2. removes ALL (!) Documents of the target database
  3. copies all Documents from source to target database
  4. removes all attachments during copy process
  5. removes all “Body” fields during copy process
  6. refreshes all views in target database

Usually there is no need for attachments and rich-text content in the test environment, so during the copy process, i remove the attachments and contents of the “Body” field.

WARNING: improper use of this agent can result in loss of data.

Please feel free to adjust the agent for your needs (change field names, leave the attachments, etc).

You find the code here, and also in the NSF file containing the same agent at the bottom of this post. Just copy the agent, start it in designer (be sure no document is open in the notes client of the target db) or server console, lean back or get a cup of coffee while notes is doing the work..

The Code

%REM
	Agent agCopyData
	Created 03.06.2014 by Frédéric Dehédin (www.fdehedin.ch)
	Description: This Agent copies all documents of the dbs specified in the List Variable "dbs". 
	Listtag is the source db, listitem value is the target db. so you can also copy data of mutliple DBs
	WARNING: the agent also removes ALL Attachments and "Body" fields
%END REM
Option Public
Option Declare

Sub Initialize
	On Error GoTo processError
	
	Dim dbs List As String 'specify like: dbs(sourceDbPath) = dbs(targetDbPath)
	
	Dim s As New NotesSession
	Dim db As NotesDatabase
	Set db = s.currentdatabase
	
	dbs("sourcefoldersource_db.nsf") = "targetfoldertarget_db.nsf"
	
	ForAll dbToProzess In dbs
		Dim dbSource As New NotesDatabase(db.server, ListTag(dbToProzess))
		If dbSource.isopen Then
			Dim dbTarget As New NotesDatabase(db.server, dbToProzess)
			If dbTarget.isopen Then
				Dim colTarget As NotesDocumentCollection
				Set colTarget = dbTarget.Alldocuments
				Call colTarget.Removeall(true)
				
				Dim colSource As NotesDocumentCollection
				Set colSource = dbSource.Alldocuments
				
				Dim docSource As NotesDocument
				Set docSource = colSource.Getfirstdocument()
				
				Dim i As Long
				Dim count As Long
				count = colSource.count
				For i = 1 To count
					
					Dim docNew As NotesDocument
					Set docNew = docSource.Copytodatabase(dbTarget)
					
					Call removeAttachment(docNew)
					Print "copy " + CStr(i) + " of " + CStr(count) + " documents. "
					Call docNew.Save(True,docSource.Isresponse)
					Set docSource = colSource.getNextDocument(docSource)
				Next
				
				Print "start refreshing views in target database."
				ForAll v In dbTarget.Views
					Call v.refresh()
				End ForAll
				Print "finished refreshing views in target database."
			End If
		End if
	End ForAll
	
	Exit Sub
processError:
	Call raiseError()
	
End Sub


%REM
	Sub removeAttachment
	Description: Comments for Sub
%END REM
Public Sub removeAttachment(doc As notesdocument)
	On Error GoTo processError
	Dim myItem As NotesItem

		Set myItem = doc.GetFirstItem("$File")	
		While Not myItem Is Nothing	
			Call myItem.Remove	
			Set myItem = doc.GetFirstItem("$File")	
		Wend	
		
		Set myItem = doc.GetFirstItem("Body")	
		While Not myItem Is Nothing	
			Call myItem.Remove	
			Set myItem = doc.GetFirstItem("Body")	
		Wend	
	
	Exit Sub
processError:
	Call raiseError()
End Sub


Function RaiseError() 
	Dim thisType As String
	Dim es As String
	'          thisType = Typename(Me)
	' Not a class, use the calling module instead
	If (thisType = "") Then thisType = GetThreadInfo(11)
	es = thisType & "::" & GetThreadInfo(10) & ": "
	If (Err = 0) Then 
		es = es + "Manually raised an error" 
	Else
		es = es +_  
		"Run time error: (" + Trim(Str(Err)) + ") " + _
		Error$ + " at line: "+ Trim(Str(Erl))
	End If
	Print es
End Function

The Download

Download Lotus Notes nsf File - Creating a test environment



---------------------
http://www.fdehedin.ch/443/creating-a-test-environment-the-easy-way
Jun 03, 2014
7 hits



Recent Blog Posts
5
Tipps and Tricks for the Java SE 8 Programmer Exam
Sun, Dec 11th 2016 4:17p   Frederic Dehedin
Recently i studied for the Java SE 8 Programmer I Exam (Java OCA for short) and was glad that i passed it on the first go. Although i’ve been practicing programming in Java several years, i decided to sustain my practical knowledge with some theoretical background and i’m happy to share my experience in this blog […]
6
Winning the IBM Collaboration Solutions Developer Competition 2016
Mon, Oct 3rd 2016 12:23p   Frederic Dehedin
Just yesterday we came back to Switzerland after our 3 Weeks holidays in Indonesia. We were in Bali, Nusa Lembongan (Island next to Bali) and Rote Island (Timor). So on the 16. September 2016, after a beautiful day on the boat diving with Manta Rays, i was eager to check the contest results and received […]




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition