Click or drag to resize

Attachment_2019_01Insert_Attachment Method

Inserts the specified attachment into EPIC
Namespace:  ASI.TAM.API.Web.EpicSDK.Attachment
Assembly:  ASI.TAM.API.Web.EpicSDK (in ASI.TAM.API.Web.EpicSDK.dll) Version: 2020.1.0.1
Syntax
int[] Insert_Attachment(
	Attachment AttachmentObject
)

Parameters

AttachmentObject
Type: ASI.TAM.API.Data.UI.AttachmentAttachment
The attachment to be inserted

Return Value

Type: Int32
A unique AttachmentID identifying the newly inserted attachment
Remarks
To use this with a new file first you need to call Upload_Attachment_File which will upload the physical file to the EPIC file server and return you a ticket ID. You then use that ticket ID to populate the FileItem property of the Attachment object to be inserted which will create an EPIC attachment containing the file. An error message will be thrown if try to insert attachment to the folder that is not accessible by the associated account type.
Examples
VB
 1' Imports SDK2011 = [Project Name].schemas.appliedsystems.com.epic.sdk._2011._01
 2' Imports SDK2009 = [Project Name].schemas.appliedsystems.com.epic.sdk._2009._07
 3
 4' Constant DATABASE preset to current database name
 5' Constant AUTHENTICATION_KEY set to current authentication key
 6' Constant USER_CODE set to a valid login user code
 7Try
 8  Dim oService As New EpicSDK_2018_01Client ' Instantiate the Service object
 9  Dim oHeader As New SDK2009_07.MessageHeader ' Instantiate the Header object
10
11  Dim oClient As New EpicSDK_2018_01Client("ServiceBinding_2016_01")
12  Dim oStreamingClient As New EpicSDKFileTransferClient("FileTransferServiceBinding")
13
14  ' Populate the database and authentication key in the Header object
15  'REQUIRED
16  oHeader.DatabaseName = DATABASE
17  oHeader.AuthenticationKey = AUTHENTICATION_KEY
18  'OPTIONAL
19  oHeader.UserCode = USER_CODE
20  oHeader.IntegrationKey = "eaa8b2df-94c0-4bac-a403-1a1b749b8e06" 'In this case we are identifing as the 3rd custom integration
21
22  Dim sFilePath As String = "C:\src\Epic\Ftr\SDKDFCT\ASI.Tools\API\Documentation\SampleCode\Files\TestAttachment.txt" 'Provide the path and file name of file 
23  Dim oFileInfo As New System.IO.FileInfo(sFilePath)              'Use class FileInfo to instantiate oFileInfo object
24  Dim iFileLength As Integer = CInt(oFileInfo.Length)             'FileInfo.Length property gets the size of the file in bytes
25
26  'Load file data to a stream that can be passed to the server.
27  Dim abFileData(iFileLength - 1) As Byte
28  Dim rdrFile As System.IO.FileStream = oFileInfo.OpenRead        'FileInfo.OpenRead creates a read-only FileStream
29  rdrFile.Read(abFileData, 0, iFileLength)                        'The Read method of the FileStream class reads a block of bytes from the stream. (abFileData=the actual number of bytes read or ‘zero if the end of the stream is reached, 0=the offset of the byte in array at which to begin reading, iFileLength=number of bytes ‘to be read) 
30  Dim memStream As New IO.MemoryStream(abFileData)                'The MemoryStream class creates a stream whose backing store is memory
31  rdrFile.Close()                                                 'Filestream.Close method closes the file stream
32
33  Dim oFileDetail As New SDK2009_07._account._attachment.FileDetailItem
34
35  'This actually uploads the file.  The returned string is used by SDK to 
36  'identify the uploaded file on the SDK server.
37  oFileDetail.TicketName = oStreamingClient.Upload_Attachment_File(oHeader, memStream)
38  oFileDetail.Extension = oFileInfo.Extension                                       'FileInfo.Extension property gets the file extension
39  oFileDetail.Length = iFileLength                                                  'FileInfo.Length property gets the length
40  oFileDetail.FileName = oFileInfo.Name                                             'FileInfo.FileName gets the file name
41
42  Dim oAttachedTos As New SDK2009_07._account._attachment.AttachedToItems
43  Dim oAttachedToItem As New SDK2009_07._account._attachment.AttachedToItem
44
45  With oAttachedToItem
46    .AttachedToID = 113168
47    'This value can be found using the lookup method(AttachmentAttachedTo)
48    .AttachedToType = "Account"
49  End With
50
51  oAttachedTos.Add(oAttachedToItem)
52
53  Dim oAttachFiles As New SDK2009_07._account._attachment.FileDetailItems
54  oAttachFiles.Add(oFileDetail)
55
56  'Set the details of the attachment object
57  Dim oAttachment As SDK2009_07._account.Attachment = New SDK2009_07._account.Attachment
58  With oAttachment
59
60    .AccountID = 113168
61    .Files = oAttachFiles
62    .AttachedTos = oAttachedTos
63
64    .Description = oFileInfo.Name
65    ''These values can be found using the lookup method(AttachmentFolder)
66    .Folder = "Documents"
67    .SubFolder1 = "Letters"
68    .ReceivedDate = New Date(2010, 12, 12) 'Required in Epic UI.  If omitted in SDK, SDK defaults current date.
69
70    .Comments = "Test Attachment"
71    ''This value can be found using the lookup method(AttachmentAccessLevel)
72    .SecurityAccessLevelCode = "Public"
73
74  End With
75
76  Dim lstAttachment As List(Of Integer) = Nothing
77
78  Try
79    ' Perform the Insert
80    lstAttachment = oService.Insert_Attachment(oHeader, oAttachment)
81
82    ' Close the service
83    oService.Close()
84
85  Catch ex As Exception
86    oService.Abort()
87    Throw
88  End Try
89
90  ' Handle output
91  Console.WriteLine("New Attachment inserted with ID: " & lstAttachment.Item(0).ToString)
92
93Catch ex As Exception
94  Console.WriteLine("Error: " & ex.Detail.Description)
95  Console.WriteLine("Press any key to exit...")
96  Console.ReadLine()
97End Try
See Also