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

Workflow Automation - VB Script Error:- Type mismatch: Vault.ObjectOpe

Former Member
Former Member
Hi All,
I have written a Workflow automation VB script to create a new object during the workflow execution. However, I am getting following error while script is executed.

Error:-  Type mismatch: Vault.ObjectOperations.CreateNewObjectExQuick 
I have attached the stack trace and the corresponding VB Script herewith.

I tried creating the new object using CreateNewObjectExQuick as well as CreateNewObject method, but resulted same error.
I tested the script by removing input property values, but above error appeared in all cases. 

I checked for existing M-Files blog and could not find satisfying answer. In one blog, it was stated that similar error occurred due to M-Files framework error and need to receive a patch from M-Files. 

I am using the latest M-File version : 19.9.8227.13  (note: this version is not available in version selection list)

Is there any body who came across and resolved  similar issue ?
Any Ideas ?

Thanks,
Hasantha  Attidiya


VB SCRIPT

OPTION EXPLICIT

Const  OT_Project = "ProjectObjectType"
COnst CL_Project ="ProjectClass"
'define work flow
Const WF_Project ="ProjectApprovalProcess"
Const WF_State ="ReviewForApproval"
' Define Properties
Const PD_Customer ="ProjCustomer"
Const PD_ProjectStatus ="ProjectStatus"
Const PD_RelatedProject ="RelatedProject"
Const PD_ProjectName ="ProjectName"


Dim ProjectObjectID : ProjectObjectID=  GetObjectID (OT_Project)      'Vault.PropertyDefOperations.Vault.ObjectTypeOperations.GetObjectTypeIDByAlias(OT_Project) 
Dim ProjectClassID : ProjectClassID= GetClassID (CL_Project)          'Vault.ClassOperations.GetObjectClassIDByAlias(CL_Project) 

Dim pidProjectName : pidProjectName =  GetPropDefIDByAlias(PD_ProjectName) ' Vault.PropertyDefOperations.GetPropertyDefIDByAlias(PD_Customer)
Dim pidProjectCustID : pidProjectCustID =  GetPropDefIDByAlias(PD_Customer) 
Dim pidRelatedProjectID : pidRelatedProjectID = GetPropDefIDByAlias(PD_RelatedProject)
Dim pidProjectStatus : pidProjectStatus = GetPropDefIDByAlias(PD_ProjectStatus) 


Dim pvalProjectCustID  : pvalProjectCustID = PropertyValues.SearchForProperty(pidProjectCustID).TypedValue.GetValueAsLookup().DisplayValue
Dim pvalRelatedProjectID : pvalRelatedProjectID = ObjVer.ID

'get workflow and initial WF state value
Dim val_WF : val_WF= Vault.WorkflowOperations.GetWorkflowIDByAlias(WF_Project)
Dim val_WF_State : val_WF_State = Vault.WorkflowOperations.GetWorkflowStateIDByAlias(WF_State)

'create property value collection to hold esch property definition value for new project objects
Dim oPropValNewProject : Set oPropValNewProject =CreateObject("MFilesAPI.PropertyValues")

'create individual place holders for each property values
Dim pvClass : Set pvClass= CreateObject("MFilesAPI.PropertyValue")
Dim pvTitle : Set pvTitle= CreateObject("MFilesAPI.PropertyValue")
Dim pvCustomer : Set pvCustomer= CreateObject("MFilesAPI.PropertyValue")
Dim pvRelatedProj : Set pvRelatedProj= CreateObject("MFilesAPI.PropertyValue")
Dim pvProjStatus : Set pvProjStatus= CreateObject("MFilesAPI.PropertyValue")
Dim pvWF : Set pvWF= CreateObject("MFilesAPI.PropertyValue")
Dim pvWFStatus : Set pvWFStatus= CreateObject("MFilesAPI.PropertyValue")
'Class property definintin

pvClass.PropertyDef =100
pvClass.Value.SetValue MFDatatypeLookup ,ProjectClassID
oPropValNewProject.Add -1, pvClass

'project title / name
pvTitle.PropertyDef = pidProjectName
pvTitle.Value.SetValue  MFDatatypeText ,"New project to be renamed"
oPropValNewProject.Add -1, pvTitle

pvProjStatus.PropertyDef = pidProjectStatus
pvProjStatus.TypedValue.SetValue MFDatatypeLookup ,0
oPropValNewProject.Add -1, pvProjStatus

'Err.Raise MFScriptCancel, "pvalProjectCustID :"  & pvalProjectCustID
pvCustomer.PropertyDef = pidProjectCustID
pvCustomer.Value.SetValue MFDatatypeText ,pvalProjectCustID
oPropValNewProject.Add -1, pvCustomer

'work flow
pvWF.PropertyDef = 38
pvWF.Value.SetValue MFDatatypeLookup ,val_WF
oPropValNewProject.Add -1, pvWF

'work flow status
pvCustomer.PropertyDef = 39
pvCustomer.Value.SetValue MFDatatypeLookup ,val_WF_State
oPropValNewProject.Add -1, pvCustomer

Dim oACl : set oACL = Vault.ObjectOperations.GetObjectPermissions(ObjVer).AccessControlList
Dim oFiles : Set oFiles = CreateObject("MFilesAPI.SourceObjectFiles")
Dim NewProjectID : NewProjectID = Vault.ObjectOperations.CreateNewObjectExQuick( OT_Project,oPropValNewProject , oFiles, False, True, oACL)

'Vault.ObjectOperations.CreateNewObjectExQuick  OT_Project,oPropValNewProject,oFiles,False, True, oACL 

Function GetPropDefIDByAlias (alias)
  Dim iPropertyDefID : iPropertyDefID = Vault.PropertyDefOperations.GetPropertyDefIDByAlias(alias)
 
  If ( iPropertyDefID = -1 ) Then
      Err.Raise MFScriptCancel, "Property definition with aliase" '& alias & "was not found , or there are multiple objects with the same alias"
    End If

  GetPropDefIDByAlias = iPropertyDefID
End Function


Function GetObjectID ( alias )
  Dim iObjectID : iObjectID = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias( alias )
    If ( iObjectID = -1) Then
      Err.Raise MFScriptCancel, "Object definition with aliase" & alias & "was not found , or there are multiple objects with the same alias"
    End If
  GetObjectID = iObjectID
End Function

Function GetClassID ( alias )
  Dim iClassID : iClassID = Vault.ClassOperations.GetObjectClassIDByAlias( alias )
    If ( iClassID = -1) Then
      Err.Raise MFScriptCancel, "Class definition with aliase" & alias & "was not found , or there are multiple objects with the same alias"
    End If '
  GetClassID = iClassID
End Function









14376.zip
  • Not sure but it seems to me you should include "set" in line 74. The code creates a new object.

    Dim NewProjectID : set NewProjectID = Vault.ObjectOperations.CreateNewObjectExQuick( OT_Project,oPropValNewProject , oFiles, False, True, oACL)

    Give it a try and see if it makes a difference.
  • Former Member
    Former Member
    Thanks for the suggestion.

    No. It didn't make a difference!
  • OK. Then you should check each of the arguments in (OT_Project,oPropValNewProject , oFiles, False, True, oACL) to see if they fit with requirements.
    OT_Project needs to be a "long" (the numerical ID for the object type). As far as I can tell you have it as an Alias.
    In line 15 you attempt to establish ProjectObjectID.
    I can't see that the active code would work but you have at the end of the line a remark that should do the trick for you. If you use that part, you should be able to use ProjectObjectID in stead of OT-Project in line 74.
    I haven't checked the other arguments for you. You may need to take a closer look at each of them.