Solved

Lotus Script - Exporting Attachments and Folder Creation

Posted on 2016-09-01
2
88 Views
Last Modified: 2016-09-06
What I have is a database with many attachments with the same name. Some in the same document or some with the same name but in two different documents. What I'm trying to do is export all of the attachments into a seperate folder based on the value of the number field "FileNumber". If any attachments with the same name exist in the same document the file name is appended with a "1".

 When trying to create a variable to cast a file number into a string I get a Type Mismatch error.
Dim FileNumberString As String
FileNumberString = CStr(FileNumber)

Below is the entire script

Sub Initialize
	Dim session As New NotesSession
	Dim db As NotesDatabase
	Dim doc As NotesDocument
	Dim nextdoc As NotesDocument
	Dim dirpath As String
	Dim view As NotesView
	Dim fullpath As String
	
	Set db = session.Currentdatabase
	Set view = db.GetView("All Documents")
	Set doc = view.Getfirstdocument
	
	Dim num As Integer
	dirpath = "D:\PlantEng"
	If (Dir$ (dirpath, 16)="") Then
		MkDir dirpath
	End If
	
	While Not doc Is Nothing
		Set nextdoc = view.getnextdocument(doc)
		
		'--Loop through all attachments in document and detach into D:\PlantEng
		Dim rtitem As Variant
		Set rtitem = doc.GetFirstItem("attachments")
		
		'--Get the unique file number attached to the document
		Dim FileNumber 
		Set FileNumber = doc.GetFirstItem("FileNumber")

		'--Create a variable to cast a file number into a string
		Dim FileNumberString As String
		FileNumberString = CStr(FileNumber)
		
		'--Create a variable to store the FileNumber as a folder
		Dim fileNumberFolder As String
		fileNumberFolder = dirpath + "\" + FileNumberString

		'--Create a new folder based on the file number
		MkDir fileNumberFolder


		'--if array of embedded objects exist them detach all attachments into D:\PlantEng
		If IsArray(rtitem.EmbeddedObjects) Then
			ForAll o In rtitem.EmbeddedObjects
				If(o.type = EMBED_ATTACHMENT) Then
					If o.name <> o.source Then
						fullpath = fileNumberFolder & "\" & o.source & +1
					Else
					fullpath = fileNumberFolder & "\"& o.source
					End If
					Call o.ExtractFile(fullpath)
				End If
			End ForAll
		End If
	Set doc = nextdoc	
	Wend
	End Sub

Open in new window

0
Comment
Question by:nftcadmins
2 Comments
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 500 total points
ID: 41781045
If you check the type of the "value" of FileNumber, you'll find that it's not a number, but a NotesItem (if it exists at all).

The method GetFirstItem will give you a NotesItem, the method GetItemValue will give you an array of values. You can get to the individual values of a NotesItem by using FileNumber.Values(n)
0
 
LVL 1

Author Closing Comment

by:nftcadmins
ID: 41786370
Worked perfect. Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

777 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