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


Parents
  • 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
Reply
  • 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
Children
No Data