The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

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, _
  • The assignement is created in a State with Run Action?

    If yes, does the metadata card of the object in the workflow, contains the user that you want to create the assignement?

  • Yes it is, and no it does not contain the user that I want to assign. Ideally I would like to assign a user group, but I don't know that that is possible. I do know the User group Id and it will be static.

  • I was able to get it working using this code for the User, do you know if it is possible to use a user group instead? When using a user group ID it did not find it.

    'Create the current user ID as typed value
    	Dim typed: Set typed = CreateObject("MFilesAPI.TypedValue")
    	Dim oLUUsers: Set oLUUsers = CreateObject("MFilesAPI.Lookups")
    	Dim oLUOneUser: Set oLUOneUser = CreateObject("MFilesAPI.Lookup")
    	
    	'Get the user
    	oLUOneUser.Item = 82' The id of the user (to be assigned)
    	oLUOneUser.Version = -1
    	Call oLUUsers.Add(-1, oLUOneUser)
    	Call typed.SetValueToMultiSelectLookup(oLUUsers)

  • Good to hear that.

    Members of the user group. Group IDs are negative, user IDs are positive. (From API Documentation).

    Try to add "-" before the id of the group.

Reply Children
  • The - in front didn't work. I guess I could create an array of Users in the user group and loop through that array and create individual assignments.

  • Any Chance you know if it is possible to set Workflow for the Assignment after creation? It seems that creating an assigment programatically ignores forcing workflow for new assignment objects.

  • 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.

  • Absolutely, thanks again!

  • 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.