• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1320
  • Last Modified:

Getting the name of the attachments in Lotus Script

I have a richtext field in a form.  When ever the user attaches documents in this field, I have to ensure that only the attachments in the form of zip or doc should be attached.  For this purpose I have to get the name of the file attachment.  In lotus script is there any way to get the name of a file attachment?  @attachmentnames is useless in this case, since I need to know the name of the attachments attached in a particular rich text field.  Any one can help in this regard?
0
sganeshkanth
Asked:
sganeshkanth
  • 5
  • 3
1 Solution
 
CRAKCommented:
You would have to save the document first as attachments can only be read in the backend. The doc. can remain open though, sou you could avoid ending up with wrong attachments in QueryClose and QueryModeChange.

After save you can access NotesUIDocument.Document (=NotesDocument)
In the NotesDocument you could access the appropriate Richttextfield using GetFirstItem. You should have both the NotesItem and NotesRichTextItem properties and methods available there.
Check the item for EmbeddedObjects (use "HasEmbedded"). If there are any available, there could be OLE objects, attachments etc. so you'd have to check and make sure you only continue on the attachments (Obj.Type). For attachments you need the "Source" property of the embeddedobject.

Check help for details!
0
 
sganeshkanthAuthor Commented:
I have already tried this option (Please see the following piece of code)

If strOldStatus <> strCurStatus Then
  If strCurStatus="320-Waiting for baseline approval" Then
    strFlag = "SAR Approval field on the Financial tab"
    Set attachementItem=doc.GetFirstItem("SARApprovalWord")
     If Not(attachementItem Is Nothing) Then
       If Isarray(attachementItem.EmbeddedObjects) Then
     Forall o In attachementItem.EmbeddedObjects
       If ( o.Type = EMBED_ATTACHMENT ) Then
         If Instr(1, o.name, ".doc", 5) > 0 Then
          strFlag = ""
         Elseif Instr(1, o.name, ".zip", 5) > 0 Then
          strFlag = ""
         End If
            End If
      End Forall
     End If
   End If
End If

In this code, while debugging I came to know that o.name is returning some hexadecimal value if the name of the attachment contains any special charecters (like hyphen, underscore etc.).  It returns the name of the attachment correctly when the name of the attachment doesn't contain special charecters.  Also, this is the case when I use o.Source instead of o.name in the above code.
0
 
sganeshkanthAuthor Commented:
I have already tried this option (Please see the following piece of code)

If strOldStatus <> strCurStatus Then
  If strCurStatus="320-Waiting for baseline approval" Then
    strFlag = "SAR Approval field on the Financial tab"
    Set attachementItem=doc.GetFirstItem("SARApprovalWord")
     If Not(attachementItem Is Nothing) Then
       If Isarray(attachementItem.EmbeddedObjects) Then
     Forall o In attachementItem.EmbeddedObjects
       If ( o.Type = EMBED_ATTACHMENT ) Then
         If Instr(1, o.name, ".doc", 5) > 0 Then
          strFlag = ""
         Elseif Instr(1, o.name, ".zip", 5) > 0 Then
          strFlag = ""
         End If
            End If
      End Forall
     End If
   End If
End If

In this code, while debugging I came to know that o.name is returning some hexadecimal value if the name of the attachment contains any special charecters (like hyphen, underscore etc.).  It returns the name of the attachment correctly when the name of the attachment doesn't contain special charecters.  Also, this is the case when I use o.Source instead of o.name in the above code.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
ZvonkoSystems architectCommented:
This is the normal behavior whit generated names when you have two attachments with same name or special characters in source file name.
0
 
CRAKCommented:
I tried your code with only minor modifications:

Sub Click(Source As Button)
     Dim WS As New NotesUIWorkspace
     Dim UIDoc As NotesUIDocument
     Dim doc As NotesDocument
     
     Set UIDoc = Ws.CurrentDocument
     Call UIdoc.Save
     Set doc = UIDoc.Document
     
     ' removed conditions
     strFlag = "SAR Approval field on the Financial tab"
     Set attachementItem=doc.GetFirstItem("RTattach") ' different fieldname
     If Not(attachementItem Is Nothing) Then
          If Isarray(attachementItem.EmbeddedObjects) Then
               Forall o In attachementItem.EmbeddedObjects
                    If ( o.Type = EMBED_ATTACHMENT ) Then
                         Messagebox o.name & " - " & o.source ' removed conditions
                    End If
               End Forall
          End If
     End If
End Sub

It showed all attachmentnames as expected, including "a_b~c'd-e.txt", for both the source as the name property.

Is there any involvement of a web-client? In URL's e.g. spaced may get translated to "%20" = ascii 32 in hex.
0
 
CRAKCommented:
Zvo's suggestion returns filenames starting with "ATT" for the duplicate names.
0
 
sganeshkanthAuthor Commented:
Yes CRAK.  I am for o.name it is showing a name starting with "ATT" as Zvo said.  In that document I found that another richtext field has the same attachment.  How to overcome this situation.
0
 
CRAKCommented:
Well, the ATT-attachments appear not to have any extension (like doc or zip), so they don't meet your validation is notes gets its way.
The least you could do is give a warning about "duplicate attachment names" to the user.

Alternatively, you could skip them since they have duplicate names. If the others are ok, so would they be!

I think the situation depends on your additional intends / demands. I can't advice you on that!
0
 
CRAKCommented:
Be careful deleting the ATT-attachment: it could be a newer version one of the other attachments!
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now