Create New Assignment - Workflow Script

I am trying to create a new assignment via a script and it keeps telling me that I have a type mismatch when creating the assignment:

Dim newValue : Set newValue = CreateObject("MFilesAPI.TypedValue")
newvalue.SetValue MFDatatypeLookup, 104
Dim MyRecordSet : set MyRecordSet = CreateObject("ADODB.RecordSet")
MyRecordSet.Open SelectStatement, oConnection

Vault.ObjectOperations.CreateNewAssignment "Part " & MyRecordSet.Fields(3) & " Revision " & MyRecordSet.Fields(4) & " Assembly Update", "Please Update the assembly for " & MyRecordSet.Fields(0) & " Revision " & MyRecordSet.Fields(1) & ". The Assembly needs to be updated because the current revision was end dated.", newvalue

Parents
  • Hello,

    Even though these parameters are optional, you have to set them to nothing in the command.

    Optional ByVal Deadline As TypedValue = 0, _
       Optional ByVal AccessControlList As AccessControlList = 0 _

    Vault.ObjectOperations.CreateNewAssignment "Part " & MyRecordSet.Fields(3) & " Revision " & MyRecordSet.Fields(4) & " Assembly Update", "Please Update the assembly for " & MyRecordSet.Fields(0) & " Revision " & MyRecordSet.Fields(1) & ". The Assembly needs to be updated because the current revision was end dated.", newvalue, nothing, nothing

    Also, I think that you need to get the values of the fields in the record set, for example MyRecordSet.Fields(3).Value

  • I added those to the creation of the assignment. It is still having issues. I believe it is with the user input not being in the correct format. Any idea how I should be setting up the AssignedToUser? I did verify that MyRecordSet.Fields(3) shows the value when testing using err.raise.

    ByVal AssignedToUser As TypedValue, _
  • I will reply tomorrow with a script for assignments, that uses CreateNewObject instead of CreateNewAssigment

  • This is the script. 

    It is not tested in this form as I had to clean it for sharing.

    Credit goes to

    Dim LU_user, LUs_users, assignmentID, assignmentListItem, assignmentList,oobjidassignment
    
    Set assignmentListItem = CreateObject("MFilesAPI.LookUp")
    Set assignmentList = CreateObject("MFilesAPI.LookUps")
    Set LU_user = CreateObject("MFilesAPI.LookUp")
    Set LUs_users = CreateObject("MFilesAPI.LookUps")
    		
    		LU_user.Item = 26 
    		LUs_users.Add -1, LU_user
    		
    		assignmentID = CreateAssignment(LUs_users, "Assignment Title, "Assignment Description")
    		
    		assignmentListItem.Item = assignmentID 
    		assignmentList.Add -1, assignmentListItem
    		
    'Here the assignment is added as Workflow Assigment, meaning that you can set in workflow automatic state transition on assigment completion		
    Dim pdAssignments : Set pdAssignments = CreateObject("MFilesAPI.PropertyValue")
    pdAssignments.PropertyDef = 79
    pdAssignments.TypedValue.SetValueToMultiSelectLookup assignmentList 		
    
    
    'Function to create the assigment
    Function CreateAssignment (assignedUsers, assignmentTitle, assignmentDescription)
    	
    	Dim oPropVals :  Set oPropVals   = CreateObject("MFilesAPI.PropertyValues")
    	Dim oOnePropVal: Set oOnePropVal = CreateObject("MFilesAPI.PropertyValue")
    	
    	 'Set class - 100 Assignment
    	oOnePropVal.PropertyDef = 100
    	oOnePropVal.TypedValue.SetValue MFDatatypeLookup, 83
    	oPropVals.Add -1, oOnePropVal
    	
    	 'Set NameorTitle
    	oOnePropVal.PropertyDef =  MFBuiltInPropertyDefNameOrTitle
    	oOnePropVal.TypedValue.SetValue MFDatatypeText, assignmentTitle
    	oPropVals.Add -1, oOnePropVal
    	
    	'set assigned users	
    	oOnePropVal.PropertyDef = 44
    	oOnePropVal.TypedValue.SetValueToMultiSelectLookup assignedUsers
    	oPropVals.Add -1, oOnePropVal
    	
    	'set assignment description
    	oOnePropVal.PropertyDef = MFBuiltInPropertyDefAssignmentDescription
    	oOnePropVal.TypedValue.SetValue MFDatatypeMultiLineText, assignmentDescription
    	oPropVals.Add -1, oOnePropVal
    
    	
    	'set workflow
    	oOnePropVal.PropertyDef = 38
    	oOnePropVal.TypedValue.SetValue MFDatatypeLookup, 124
    	oPropVals.Add -1, oOnePropVal
    
    	'set workflow state
    	oOnePropVal.PropertyDef = 39
    	oOnePropVal.TypedValue.SetValue MFDatatypeLookup, 272
    	oPropVals.Add -1, oOnePropVal
    	
    	'set objtypeid
    	Dim newObjectID : newObjectID = 10    
    	
    	Dim objNewObjectSourceFiles: Set objNewObjectSourceFiles = CreateObject("MFilesAPI.SourceObjectFiles")	
    	Dim bolIsSingleFileDocument: bolIsSingleFileDocument = False
    		
    	' Create Object and Checkin
    	Dim oVaP : Set oVaP = CreateObject("MFilesAPI.ObjectVersionAndProperties")
    	
    	oVaP = vault.ObjectOperations.CreateNewObjectExQuick(newObjectID, oPropVals, objNewObjectSourceFiles, bolIsSingleFileDocument, true, nothing)
    	CreateAssignment = oVaP
    
    End function

  • Thank you, this is exactly what I was looking for.

  • Please keep in mind that you need to replace some ID's as they are hardcoded from our environment.

  • Can you tell me where the value 83 comes from when creating the assignment?

    	 'Set class - 100 Assignment
    	oOnePropVal.PropertyDef = 100
    	oOnePropVal.TypedValue.SetValue MFDatatypeLookup, 83
    	oPropVals.Add -1, oOnePropVal

  • Assignment Class.

    I created an assignment class specifically for a process. 

    In classes, you have to unhide builtin classes to view for example assignment classes.

  • So in my case with the built in assignment class it would be -100?

Reply Children
No Data