This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Script to create documents via barcode

I've got a couple of different classes of document that I'm looking at automatically importing into M-Files via the File Source arrangement.

The idea I had, after seeing all the posts about using barcodes to locate existing documents in M-Files and updating them, or to add barcodes to existing documents, was to configure the barcode with appropriate information, including a Class Identifier, and have M-Files handle it.

Where I'm stuck, is that I'm not sure where the script should go (i.e. event handler, workflow with automatic state transition, other?), as I want M-Files to automatically create new documents based on the details in the barcode.

My intention was to use a compound barcode, i.e. DocClass-JobID-ClientID, and parse the values into appropriate properties, as the values are used in M-Files as external IDs anyway. Documents would have the barcode automatically generated by the external software, for use as automatic entry into M-Files.
As I understand it, the Importer can deal with single value barcodes (or OCR text values, for that matter), but since I want to preset the document type and the other information in the barcode, I don't know whether a workflow, event handler or similar would be the appropriate place for it. I've got workarounds available (separate file import tool per document class, reading from a separate folder, as an example) but would really prefer to be able to parse the barcode, set the document class and properties, and be done.

Any suggestions?
Parents
  • Former Member
    Former Member
    I would set this in a Workflow. Have this particular file source set the workflow.

    That will automatically create a new document (as unclassified). Then, parse the barcode and set the class and other properties.

    If these are being passed digitally, another idea is to put the properties in the file name. Instead of a compound barcode, set the filename to the compound components. This will be way faster, and avoid a layer of barcode generation and OCR. Below is a script we use to take the SSN from the file name, find the appropriate client, and set some other properties.

    Option Explicit

    'Script to import tax returns from Lacerte into M-Files
    'Split file name by "@", take last string (3rd, index 2)
    'E.g., INDV2016@SMITH@999-99-9999

    ' Get SSN from file name
    '=======================
    Dim sFileName : sFileName = PropertyValues.SearchForProperty(0).TypedValue.DisplayValue 'Get file name
    Dim sSplits : sSplits = Split(sFileName, "@", -1, 1) 'Split file name by @

    'Create Tax Return Object
    '========================
    If UBound(sSplits) = 2 And Len(sSplits(2)) = 11 Then

    ' Find Client
    '==============
    Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")

    'Add class to search
    Dim oSearchCondition1 : Set oSearchCondition1 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition1.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition1.Expression.DataPropertyValuePropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeMultiSelectLookup, 2 ' Client Class
    oSearchConditions.Add -1, oSearchCondition1

    'Add SSN to search
    Dim oSearchCondition2 : Set oSearchCondition2 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition2.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition2.Expression.DataPropertyValuePropertyDef = 1021 ' SSN Property
    oSearchCondition2.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeText, sSplits(2) ' Client Class
    oSearchConditions.Add -1, oSearchCondition2

    'Search
    Dim oSearchResults: Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFilesAPI.MFSearchFlags.MFSearchFlagNone, false)
    'Err.Raise MFScriptCancel, "Clients: " & oSearchResults.Count

    If oSearchResults.Count = 1 Then
    'Get ClientID
    'Err.Raise MFScriptCancel, "Clients: " & oSearchResults.Item(1).ObjVer.Id

    'Set Properties
    '=================

    ' Create property definitions
    Dim oPropertyValues : Set oPropertyValues = CreateObject("MFilesAPI.PropertyValues")

    ' Add "Client" Property. ID = 1020
    Dim oPropertyValue0 : Set oPropertyValue0 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue0.PropertyDef = 1020 'Client
    oPropertyValue0.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeMultiSelectLookup, oSearchResults.Item(1).ObjVer.Id ' ClientID
    oPropertyValues.Add -1, oPropertyValue0

    ' Add "Year" Property. 2016 ID = 3
    Dim oPropertyValue1 : Set oPropertyValue1 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue1.PropertyDef = 1028 'Year
    oPropertyValue1.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeLookup, 3 ' 2016
    oPropertyValues.Add -1, oPropertyValue1

    ' Add 'Class' property to Tax Return (ID = 4)
    Dim oPropertyValue2 : Set oPropertyValue2 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue2.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oPropertyValue2.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeLookup, 4
    oPropertyValues.Add -1, oPropertyValue2

    'Add "Single File" Property
    Dim oPropertyValue3 : Set oPropertyValue3 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue3.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefSingleFileObject
    oPropertyValue3.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeBoolean, True
    oPropertyValues.Add -1, oPropertyValue3

    'Add Properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropertyValues
    End If


    End If
Reply
  • Former Member
    Former Member
    I would set this in a Workflow. Have this particular file source set the workflow.

    That will automatically create a new document (as unclassified). Then, parse the barcode and set the class and other properties.

    If these are being passed digitally, another idea is to put the properties in the file name. Instead of a compound barcode, set the filename to the compound components. This will be way faster, and avoid a layer of barcode generation and OCR. Below is a script we use to take the SSN from the file name, find the appropriate client, and set some other properties.

    Option Explicit

    'Script to import tax returns from Lacerte into M-Files
    'Split file name by "@", take last string (3rd, index 2)
    'E.g., INDV2016@SMITH@999-99-9999

    ' Get SSN from file name
    '=======================
    Dim sFileName : sFileName = PropertyValues.SearchForProperty(0).TypedValue.DisplayValue 'Get file name
    Dim sSplits : sSplits = Split(sFileName, "@", -1, 1) 'Split file name by @

    'Create Tax Return Object
    '========================
    If UBound(sSplits) = 2 And Len(sSplits(2)) = 11 Then

    ' Find Client
    '==============
    Dim oSearchConditions : Set oSearchConditions = CreateObject("MFilesAPI.SearchConditions")

    'Add class to search
    Dim oSearchCondition1 : Set oSearchCondition1 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition1.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition1.Expression.DataPropertyValuePropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oSearchCondition1.TypedValue.SetValue MFDataType.MFDatatypeMultiSelectLookup, 2 ' Client Class
    oSearchConditions.Add -1, oSearchCondition1

    'Add SSN to search
    Dim oSearchCondition2 : Set oSearchCondition2 = CreateObject("MFilesAPI.SearchCondition")
    oSearchCondition2.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
    oSearchCondition2.Expression.DataPropertyValuePropertyDef = 1021 ' SSN Property
    oSearchCondition2.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeText, sSplits(2) ' Client Class
    oSearchConditions.Add -1, oSearchCondition2

    'Search
    Dim oSearchResults: Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFilesAPI.MFSearchFlags.MFSearchFlagNone, false)
    'Err.Raise MFScriptCancel, "Clients: " & oSearchResults.Count

    If oSearchResults.Count = 1 Then
    'Get ClientID
    'Err.Raise MFScriptCancel, "Clients: " & oSearchResults.Item(1).ObjVer.Id

    'Set Properties
    '=================

    ' Create property definitions
    Dim oPropertyValues : Set oPropertyValues = CreateObject("MFilesAPI.PropertyValues")

    ' Add "Client" Property. ID = 1020
    Dim oPropertyValue0 : Set oPropertyValue0 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue0.PropertyDef = 1020 'Client
    oPropertyValue0.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeMultiSelectLookup, oSearchResults.Item(1).ObjVer.Id ' ClientID
    oPropertyValues.Add -1, oPropertyValue0

    ' Add "Year" Property. 2016 ID = 3
    Dim oPropertyValue1 : Set oPropertyValue1 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue1.PropertyDef = 1028 'Year
    oPropertyValue1.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeLookup, 3 ' 2016
    oPropertyValues.Add -1, oPropertyValue1

    ' Add 'Class' property to Tax Return (ID = 4)
    Dim oPropertyValue2 : Set oPropertyValue2 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue2.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefClass
    oPropertyValue2.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeLookup, 4
    oPropertyValues.Add -1, oPropertyValue2

    'Add "Single File" Property
    Dim oPropertyValue3 : Set oPropertyValue3 = CreateObject("MFilesAPI.PropertyValue")
    oPropertyValue3.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefSingleFileObject
    oPropertyValue3.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeBoolean, True
    oPropertyValues.Add -1, oPropertyValue3

    'Add Properties
    Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropertyValues
    End If


    End If
Children
No Data