AutoStore: Create a Custom RRT


Have you ever needed to dynamically create a custom RRT for an AutoStore process?

In my previous post AutoCapture Default Date, I described my very first AutoStore script where the value of an Invoice Date field in an AutoCapture Vendor Invoices form was assigned a default value of the day prior from the current date.

This Invoice Date needs to be part of the file name, however its format contains slash (/) characters that cannot be part of the file name. So, we'll use the AutoStore VB/JScript process component to create a new RRT that's more friendly.

To do so, we'll look at how to do the following:
  • Bring the existing Invoice Date value into the script
  • Reformat the Invoice Date to a Windows-friendly file name
  • Output the reformatted Invoice Date to a new custom RRT

After adding the VB/JScript process component in between the capture component and the Send to Folder route component of the configuration file, we open the AutoCapture component to configure the Vendor Invoices form to setup the VB/JScript process component.

Go to the Fields tab, create a new field, assign m_InvoiceDate to the Name, and add the AutoCapture Invoice Date field RRT as the Value for this field.

In the General tab, enter VendorInvoices for the Name, and click on the ellipsis button next to the Script path, which opens up the script editor. Doing so creates a starting script template with two event handlers added. The first is the work to be performed when the script is loaded (VendorInvoices_OnLoad), and the other with the script is unloaded (VendorInvoices_OnUnload).

OnLoad and OnUnload Event Handlers
Sub VendorInvoices_OnLoad

End Sub

Sub VendorInvoices_OnUnload

End Sub

Fortunately, the VB/JScript component's Help file has a simple example to show information in the Status Monitor. So, to confirm that the script recognizes the value of m_InvoiceDate, we can set EKOManager.StatusMessage to see the date entered in AutoCapture show in the Status Monitor.

EKOManager.StatusMessage to output a message inside the Status Monitor
Sub VendorInvoices_OnLoad
    EKOManager.StatusMessage("VendorInvoices_OnLoad Starting ...")
    EKOManager.StatusMessage("m_InvoiceDate=" & m_InvoiceDate)
    EKOManager.StatusMessage("VendorInvoices_OnLoad Finished.")
End Sub

Sub VendorInvoices_OnUnload

End Sub

If we save and run the configuration with the script as-is up to this point, the Invoice Date value would be displayed in the Status Monitor with its format as mm/dd/yyyy. OK, that wasn't too hard. Now, onto reformatting the Invoice Date.

For this example, I placed a custom function named FormatInvoiceDate(), which takes a single input parameter named InvoiceDate. The date parts are taken and reassembled into a date formatted as yyyy-mm-dd. The string variable strInvoiceDate will hold that reformatted Invoice Date value.

FormatInvoiceDate() Function returns the Invoice Date reformatted
Sub VendorInvoices_OnLoad
    EKOManager.StatusMessage("VendorInvoices_OnLoad Starting ...")
    EKOManager.StatusMessage("m_InvoiceDate=" & m_InvoiceDate)

    ' Reformat the Invoice Date
    Dim strInvoiceDate : strInvoiceDate = FormatInvoiceDate(m_InvoiceDate)

    EKOManager.StatusMessage("VendorInvoices_OnLoad Finished.")
End Sub

Sub VendorInvoices_OnUnload

End Sub

' Format the Invoice Date as yyyy-mm-dd
Function FormatInvoiceDate(ByVal InvoiceDate)
  Dim strReturn : strReturn = ""

Dim dteInvoiceDate : dteInvoiceDate = CDate(InvoiceDate)
Dim strY4 : strY4 = DatePart("yyyy", dteInvoiceDate)
Dim strM2 : strM2 = Right("0" & DatePart("m", dteInvoiceDate), 2)
Dim strD2 : strD2 = Right("0" & DatePart("d", dteInvoiceDate), 2)

strReturn = strY4 & "-" & strM2 & "-" & strD2

FormatInvoiceDate = strReturn
End Function

The final part is to create the RRT for that reformatted Invoice Date value. Unfortunately, there was not an example of how to do this inside of the Help file, but the following shows how to do so.

Declare an object variable named Topic, and set it to KnowledgeContent.GetTopicInterface. Now, we can use its Replace method to create the new RRT, and set its value by providing the string variable of the reformatted date.

Creating an RRT with the Date reformatted
Sub VendorInvoices_OnLoad
    EKOManager.StatusMessage("VendorInvoices_OnLoad Starting ...")
    EKOManager.StatusMessage("m_InvoiceDate=" & m_InvoiceDate)

    ' Reformat the Invoice Date
    Dim strInvoiceDate : strInvoiceDate = FormatInvoiceDate(m_InvoiceDate)

    ' Create RRT
    Set Topic = KnowledgeContent.GetTopicInterface
    If Not (Topic Is Nothing) Then
        Topic.Replace "~USR::%InvoiceDate%~", strInvoiceDate
    End If

    EKOManager.StatusMessage("VendorInvoices_OnLoad Finished.")
End Sub

Sub VendorInvoices_OnUnload

End Sub

' Format the Invoice Date as yyyy-mm-dd
Function FormatInvoiceDate(ByVal InvoiceDate)
  Dim strReturn : strReturn = ""

Dim dteInvoiceDate : dteInvoiceDate = CDate(InvoiceDate)
Dim strY4 : strY4 = DatePart("yyyy", dteInvoiceDate)
Dim strM2 : strM2 = Right("0" & DatePart("m", dteInvoiceDate), 2)
Dim strD2 : strD2 = Right("0" & DatePart("d", dteInvoiceDate), 2)

strReturn = strY4 & "-" & strM2 & "-" & strD2

FormatInvoiceDate = strReturn
End Function

Now, to actually use the RRT that was just created. Normally, the RRTs for a given component are displayed in the Available RRTs list, and ready for drag-and-drop. To use an RRT created in a script, these would need to be manually typed, or copied and pasted.

For the Rename File Schema in the Send to Folder Route component, we can incorporate a blend of various RRTs, such as in the following manner:

~ACC::%Invoice Number%~_~USR::%InvoiceDate%~ ~STF::Counter~~STF::FileExt~

There you have it – my second-ever AutoStore script. Solving this problem turned out to be a fun learning experience at the time, and years later, I continue to draw on the lessons learned from this challenge.

At the the time I learned to do this, AutoStore 4.6 was the current platform. Starting with AutoStore 6.0, the built-in Data Filter process component could also reformat a date during runtime without scripting, and is much easier to do. We'll cover how to do this in my next post.

Comments

Popular posts from this blog

VBScript: Ensure Backslash Folder Path

AutoStore: Workflow Loop Example