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

Help with VBScript to Create Document in Event Handler

Former Member
Former Member
Hi All,

I have search the forum and have managed to covert VB to VBScript but i still cant get the following to work. I am being held up on the final line of code which creates the object with a Type Mismatch Error.

Can someone please help.

here is my code;

Option Explicit

Dim oClass: Set oClass = CreateObject("MFilesAPI.PropertyValue")
Dim oName: Set oName = CreateObject("MFilesAPI.PropertyValue")
Dim oPropValsNew: Set oPropValsNew = CreateObject("MFilesAPI.PropertyValues")

'Set Name
oName.PropertyDef = MFBuiltInPropertyDefNameOrTitle
oName.TypedValue.SetValue MFDatatypeText, "Test"
oPropValsNew.Add -1, oName

'Set Class
oClass.PropertyDef = MFBuiltInPropertyDefClass
oClass.TypedValue.SetValue MFDatatypeLookup, 0
oPropValsNew.Add -1, oClass

vault.ObjectOperations.CreateNewObject 0, oPropValsNew


  • Former Member
    Former Member
    Quickly it seems that you are missing a couple of things: SFD/MFD property, sourcefiles object and access control list for permissions. Here are quick modifications that might do the trick (not tested):

    Option Explicit

    Dim oClass: Set oClass = CreateObject("MFilesAPI.PropertyValue")
    Dim oName: Set oName = CreateObject("MFilesAPI.PropertyValue")
    Dim oSFD: Set oSFD = CreateObject("MFilesAPI.PropertyValue")
    Dim oPropValsNew: Set oPropValsNew = CreateObject("MFilesAPI.PropertyValues")
    Dim oSourceFiles: Set oSourceFiles = CreateObject("MFilesAPI.SourceObjectFiles")
    Dim oACL: Set oACL = CreateObject("MFilesAPI.AccessControlList")

    'Set Name
    oName.PropertyDef = MFBuiltInPropertyDefNameOrTitle
    oName.TypedValue.SetValue MFDatatypeText, "Test"
    oPropValsNew.Add -1, oName

    'Set Class
    oClass.PropertyDef = MFBuiltInPropertyDefClass
    oClass.TypedValue.SetValue MFDatatypeLookup, 0
    oPropValsNew.Add -1, oClass

    'Set SFD/MFD
    oSFD.PropertyDef = 22
    oSFD.TypedValue.SetValue MFDatatypeBoolean, false
    oPropValsNew.Add -1, oSFD

    dim props
    set props = vault.ObjectOperations.CreateNewObject( MFBuiltInObjectType.MFBuiltInObjectTypeDocument, oPropValsNew, oSourceFiles, oACL)
    Vault.ObjectOperations.CheckIn( props.ObjVer )


    In this simple code the ACL will stay empty, which means that you will only see the created object with administrative permissions in the vault (make a search or a view that shows latest documents in the vault as an administrator).

    Hopefully this helps.

    Best regards,
    Samppa
  • Former Member
    Former Member
    Thankyou for reply Samppa,

    This gives me a better Idea of how to structure.

    This script however gives me the following error.

    'The maximum number of objects created for the object type '0' was exceeded during the execution of a script.'

    I want to create an additional document when a document is added to m-files.

    I am therefore using the "AfterCreateNewObjectFinalise" which I beleive is the correct event.

    Ahhhhh...

    I just realised what is happening. Im creating a nasty loop. When my script document is created it fires the same script trying to create a new document again, and again.

    Any ideas on how i can catch this/prevent this loop.


  • Former Member
    Former Member
    Got it all work ok now.

    As I only want this to happen on a particular document class i just got it to check before running script which creates an alternative document class.

    I will Post the final code once complete.