So, here are some codes of a method explaining how we can move attachments in Encompass to a specified document folder
This method MoveToFolder
takes two parameters, docTitle
and docBucket
, both of type string
. It returns a bool
value indicating whether or not the document was moved to the folder.
Inside the method, first, it gets the current loan and the session from the Encompass application. It then creates a new list of attachments to be added to the folder, sets two boolean values to false
, and sets the cursor to a waiting state.
Then, it loops through each attachment in the current loan’s attachments collection. It splits the docTitle
parameter into a list of strings using a comma as a delimiter. It then checks if the attachment’s title matches any of the strings in the list and if the attachment does not have a document. If both conditions are true, it adds the attachment to the attachmentList
and sets the folder
boolean to true
.
Next, it loops through each tracked document in the current loan’s log’s tracked documents collection. It checks if the docBucket
parameter matches the title of any of the tracked documents. If it does, it sets the flag
boolean to true
.
If the flag
boolean is false, it gets the document template with the docBucket
title from the session’s loans templates documents collection. It then adds a new tracked document to the current loan’s log’s tracked documents collection using the AddFromTemplate
method, passing in the document template and the milestone event name of the next milestone in the loan’s log.
Then, it gets a list of tracked documents with the docBucket
title from the current loan’s log’s tracked documents collection. If the list is not empty, it gets the first tracked document from the list.
Finally, if the folder
boolean is true, it loops through each attachment in the attachmentList
and attaches it to the tracked document. The method then returns the folder
boolean value, indicating whether or not the document was moved to the folder.
VB.net
Public Function MoveToFolder(ByVal docTitle As String, ByVal docBucket As String) As Boolean
Dim currentLoan As Loan = EncompassApplication.CurrentLoan
Dim session As Session = DirectCast(currentLoan, SessionBoundObject).Session
Dim attachmentList As New List(Of Attachment)()
Dim folder As Boolean = False
Dim flag As Boolean = False
Cursor.Current = Cursors.WaitCursor
For Each attachment As Attachment In currentLoan.Attachments
Dim stringList As New List(Of String)()
Try
Dim str1 As String = docTitle
Dim chArray As Char() = {“,”c}
For Each str2 As String In str1.Split(chArray)
stringList.Add(str2)
Next
Catch
stringList.Add(docTitle)
End Try
For Each str As String In stringList
If attachment.Title = str AndAlso attachment.GetDocument() Is Nothing Then
attachmentList.Add(attachment)
folder = True
End If
Next
Next
For Each trackedDocument As TrackedDocument In DirectCast(currentLoan.Log.TrackedDocuments, LoanLogEntryCollection)
If trackedDocument.Title = docBucket Then
flag = True
Exit For
End If
Next
If Not flag Then
Dim templateByTitle As DocumentTemplate = session.Loans.Templates.Documents.GetTemplateByTitle(docBucket)
currentLoan.Log.TrackedDocuments.AddFromTemplate(templateByTitle, EncompassApplication.CurrentLoan.Log.MilestoneEvents.NextEvent.MilestoneName)
End If
Dim documentsByTitle As LogEntryList = currentLoan.Log.TrackedDocuments.GetDocumentsByTitle(docBucket)
If CType(documentsByTitle, CollectionBase).Count > 0 Then
Dim trackedDocument As TrackedDocument = CType(documentsByTitle(0), TrackedDocument)
If folder Then
For Each attachment As Attachment In attachmentList
trackedDocument.Attach(attachment)
Next
End If
End If
Return folder
End Function