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

Add new file to existing Document collection

Former Member
Former Member
I am creating new file to Temp folder, uploading it to M-Files (via client) and trying to add it as additional member to existing Document collection.
The problem with my current code is that it overrides everything in existing Document collection with additional file I am trying to add. I want to add additional file but it becomes the only one existing in Document collection after running this code.

    ' Execute search for existing Document Collections
    Set oObjectSearchResults = oVault.ObjectSearchOperations.SearchForObjectsByConditions(oSearchConditions, MFSearchFlagNone, False)
           
    'MsgBox ("There were " & oObjectSearchResults.Count & " objects")
           
    ' Get a reference to existing Document Collection
    Set oDocumentCollectionOVAP = oVault.ObjectOperations.GetObjectVersionAndProperties(oObjectSearchResults.Item(1).ObjVer)
     
        ' Add current file to Document Collection
        lookup.Item = oOldDocumentOVAP.ObjVer.ID
        lookup.Version = -1
        lookups.Add -1, lookup
        propertyValue.TypedValue.SetValueToMultiSelectLookup lookups
        propertyValue.PropertyDef = MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefCollectionMemberDocuments
     
        ' Check out Document Collection
        If Not (oVault.ObjectOperations.IsObjectCheckedOut(oDocumentCollectionOVAP.ObjVer.ObjID)) Then
            oVault.ObjectOperations.CheckOut oDocumentCollectionOVAP.ObjVer.ObjID
        End If

        ' Save changes to Document Collection object
        Set oDocumentCollectionOVAP = oVault.ObjectOperations.GetLatestObjectVersionAndProperties(oDocumentCollectionOVAP.ObjVer.ObjID, True, False)
        oVault.ObjectPropertyOperations.SetProperty oDocumentCollectionOVAP.ObjVer, propertyValue

        ' Check in Document Collection object
        oVault.ObjectOperations.CheckIn oDocumentCollectionOVAP.ObjVer
Parents
  • Without going into details in your code:
    You should probably get a list of existing documents before you add the new document. Currently it seems like you create a new list, add the new document to it and then overwrite the existing list thereby removing all existing documents from the collection.
    Perhaps there is a better way - I haven't done any scripting with Document Collection.
Reply
  • Without going into details in your code:
    You should probably get a list of existing documents before you add the new document. Currently it seems like you create a new list, add the new document to it and then overwrite the existing list thereby removing all existing documents from the collection.
    Perhaps there is a better way - I haven't done any scripting with Document Collection.
Children
No Data