Solved

Lotusscript, sending attachments from one database to another

Posted on 2006-07-21
13
886 Views
Last Modified: 2013-12-18
Hi Guys,

First off, although I have a good understanding of Notes I am not a Notes developer.

We have a script that we use to send documents from one database for use in another when required.

This scripts when run on one more documents does the job just fine, ensuring that existing documents are just updated and not recreated.

Now we need also to send over attachments, documents may have none, one or more attachments.

Existing working script below, any help would be appreciated, thks


Sub Initialize
      Dim ss As New notessession
      Dim sourcedb As notesdatabase
      Dim col As notesdocumentcollection
      Dim sourcedoc As notesdocument
      Dim sourcertitem As notesrichtextitem
      Dim destdb As notesdatabase
      Dim destview As notesview
      Dim destdoc As notesdocument
      
      Dim n As Variant
      Dim unid As String
      
      Set sourcedb = ss.currentdatabase
      Set destdb = New notesdatabase("server/domain", "folder\db.nsf")
      Set destview = destdb.getview("DB")
      
      Set col = sourcedb.unprocesseddocuments
      Set sourcedoc = col.getfirstdocument()
      While Not(sourcedoc Is Nothing)
            unid = sourcedoc.DocID(0)
            Set destdoc = destview.getdocumentbykey(unid)
            If destdoc Is Nothing Then
                  Set destdoc = New notesdocument(destdb)
            End If
            Set sourcertitem = sourcedoc.getfirstitem("Body")
            If destdoc.hasitem("body") Then
                  Call destdoc.removeitem("body")
            End If
            Call sourcertitem.copyitemtodocument(destdoc, "Body")
            If destdoc.hasitem("$Fonts") Then
                  Call destdoc.removeitem("$Fonts")
            End If
            Set n = sourcedoc.getfirstitem("$Fonts")
            Call n.copyitemtodocument(destdoc,"")
            Dim articleItem As notesitem
            Set articleItem = sourcedoc.getfirstitem( "body" )
            
            Call destdoc.replaceitemvalue("pricingRules", "")
            Call destdoc.replaceitemvalue("display1", sourcedoc.Title)
            Call destdoc.replaceitemvalue("display2", "")
            Call destdoc.replaceitemvalue("Form", "Report")
            
            
            Call destdoc.save(True, False)
            
            Set sourcedoc = col.getnextdocument(sourcedoc)
      Wend
      
End Sub
0
Comment
Question by:tashsmith
  • 7
  • 3
  • 2
  • +1
13 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
Comment Utility
What's your problem? Attachments aren't transferred at the moment? Apparently, the attachments are not in the Body-field but in some other field, or in the document itself? Do you know where thery are stored?
0
 

Author Comment

by:tashsmith
Comment Utility
Attachments are not being transferred, they are attached to the document in an rtf field. We now need them to transfer as well.
0
 
LVL 19

Accepted Solution

by:
madheeswar earned 100 total points
Comment Utility
u should be using Copyallitems to copy those attachments.
Else, u need to Extract the attachment and then attach to the new doc in the other db.
0
 

Author Comment

by:tashsmith
Comment Utility
if I use Copyallitems presumably I will transfer all the document including all the fields, which we do not want to do.
Is this the case?
0
 
LVL 18

Assisted Solution

by:marilyng
marilyng earned 300 total points
Comment Utility
Wouldn't just duplicating this section for the rtItem that holds the attachments do it?

Set sourcertitem = sourcedoc.getfirstitem("rtItemwAttachments")
If destdoc.hasitem("rtItemwAttachments") Then
               Call destdoc.removeitem("rtItemwAttachments")
          End If
Call sourcertitem.copyitemtodocument(destdoc, "rtItemwAttachments")
0
 
LVL 46

Assisted Solution

by:Sjef Bosman
Sjef Bosman earned 100 total points
Comment Utility
Indeed, the same you already did for the Body field??
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:tashsmith
Comment Utility
ok guys thanks, gonna give that a go...
0
 

Author Comment

by:tashsmith
Comment Utility
ok right well,

I included this code into the original code and the attachment/s tranferred to the new document.
However on opening the destination document I get the following error 'note item not found'.

When the document is in edit mode the "attach" field does display a empty icon and the file launches successfully.
I then saved the documents and looked at the field values in document properties.

The "attach" field shows no value.
The "ListAttachNames" that uses formulae @AttachmentNames, as lists the attachments name just fine.
The $File field shows the file details

However when I open the document again, the attach field appears empty, not even a empty icon box, all field values remain as above, but it is not possible to delete from the 'attach' rtf field as nothing is seen either in the properties list or in the form itself.

Ive done some digging and it seems this is a bug in Designer versions lower than 6.5.5 Im running 6.5.4... happy days

This problem is documented  here with various options for a fix.

http://www-1.ibm.com/support/docview.wss?&uid=swg21197459

The only resonable option for me is the workaround suggesting the ExtractFile method, pasted below...
Although I would want to script to delete the files stored on the hardrive after reattaching, I assume the Kill line does this?


Workaround

To fix the original source file attachment, save it to disk, delete it from the Notes document, save the Notes document, and then reattach the file.

To code around the issue in earlier releases, do not use a CopyItem method. Instead use the ExtractFile method (of the NotesEmbeddedObjects class) to write the attachment to disk. Then use the EmbedObject method (of the NotesRichTextItem class) to attach the file.

For example:

'Unremark the line below copying to a new document
'Dim RTtarget as new NotesRichTextItem(targetdoc, "Body")
Set RTtarget=targetdoc.GetFirstItem("Body")
Set RTsource=sourcedoc.GetFirstItem("Body")
Forall o In RTsource.embeddedobjects
If o.type=EMBED_ATTACHMENT Then
Call o.extractfile("C:\" + o.source)
Call RTtarget.embedobject(Embed_Attachment, "", "C:\" + o.source)
Kill "C:\" + o.source
End If
End Forall



0
 

Author Comment

by:tashsmith
Comment Utility
I ran the script using Notes 7 and am still experiencing the same problems, have you guys come across this problem?
0
 
LVL 18

Expert Comment

by:marilyng
Comment Utility
Probably not, because I would just copy the entire document over and then delete the fields I don't need and change the form name.   However, since Item retains all properties of RT item, then try:

targetdoc.ItemName = source.docItem

0
 

Author Comment

by:tashsmith
Comment Utility
OK I got this to work, at the moment it seems to do the job, but Im going to test some more...


Dim RTtarget As New NotesRichTextItem(destdoc, "attach")
            Set RTtarget=destdoc.GetFirstItem("attach")
            Set RTsource=sourcedoc.GetFirstItem("Additional")
            Forall o In RTsource.embeddedobjects
                  If o.type=EMBED_ATTACHMENT Then
                        Call o.extractfile("C:\Desktop" + o.source)
                        Call RTtarget.embedobject(Embed_Attachment, "", "C:\Desktop" + o.source)
                        Kill "C:\Desktop" + o.source
                  End If
            End Forall
0
 
LVL 18

Expert Comment

by:marilyng
Comment Utility
tashsmith,

If this is running on the server, then I'm thinking that the source directory on the server would be the Notes\data directory, else the detach might not function to a directory outside of notes.

But I could be wrong.. good luck.
0
 

Author Comment

by:tashsmith
Comment Utility
thanks guys, got there in the end, you all helped to the final solution so awarded accordingly...

marilyng the attachments are detaching to my hardrive just fine...

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Lotus notes email code 2 113
Add a cc field to email code 6 94
Domino Server 2 68
Installing Lotus Notes on Citrix XenApp 3 85
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

743 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

18 Experts available now in Live!

Get 1:1 Help Now