Hi all,
Is there a way to set a specific Workflow from an import using Replication content ?
Exported documents don't have workflow defined on Vault source and I need to force a workflow on destination Vault.
Thanks for your help !
Hi all,
Is there a way to set a specific Workflow from an import using Replication content ?
Exported documents don't have workflow defined on Vault source and I need to force a workflow on destination Vault.
Thanks for your help !
You probably use some unique propertyvalue or combination of values in the source vault to filter out the documents for replication. In that case you should be able to create an event handler in the destination vault using the same filter settings and let that event handler add your workflow. You could use the workflow property (38) as additional element in the filter to avoid a loop (only run event handler action if Workflow is empty).
You probably use some unique propertyvalue or combination of values in the source vault to filter out the documents for replication. In that case you should be able to create an event handler in the destination vault using the same filter settings and let that event handler add your workflow. You could use the workflow property (38) as additional element in the filter to avoid a loop (only run event handler action if Workflow is empty).
Hi, thanks for your answer should I use this event handler
Replication: AfterCreateNewObjectFinalize ?
I would go with BeforeCheckInChanges. According to the User Guide: When executing the AfterCreateNewObjectFinalize event handler, the object may have already been checked in. For this reason, the metadata or files can no longer be modified during operation of the event handler, and thus the event handler is only suitable for validating changes.
See https://www.m-files.com/user-guide/latest/eng/Event_handlers_variables.html
Not working :( maybe you have an idea with code below
Set objVersionAndProps = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
set refpropertyObjects = Vault.ObjectOperations.getrelationships(ObjVer,1)
Dim compta: compta = objVersionAndProps.SearchForProperty( 100 ).TypedValue.GetLookupID
'documents
If ObjVer.Type= 0 _
then
'Document class
if compta = 66 _
then
'All referenced objects
For Each ID in refpropertyObjects
Set latetesObjVerRef = Vault.objectOperations.GetLatestObjectVersionAndProperties(ID.ObjVer.ObjID,False,False)
Set objRefVersionAndProps = Vault.ObjectPropertyOperations.GetProperties(latetesObjVerRef.Objver)
Dim oPropValNew: Set oPropValNew = CreateObject("MFilesAPI.PropertyValue")
Dim oPropValsNew: Set oPropValsNew = CreateObject("MFilesAPI.PropertyValues")
oPropValNew.PropertyDef = 38
oPropValNew.TypedValue.SetValue MFDatatypeLookup, 104
oPropValsNew.Add -1, oPropValNew
oPropValNew.PropertyDef = 39
oPropValNew.TypedValue.SetValue MFDatatypeLookup, 130
oPropValsNew.Add -1, oPropValNew
Vault.ObjectPropertyOperations.SetProperties latetesObjVerRef.Objver, oPropValsNew
next
end if
end if
I tried this as well, import succeed but no workflow set up
Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True )
'Change Workflow property in the PropertyValues collection to 115 (HR - Employee On-boarding)
PropertyValues.SearchForProperty(38).TypedValue.SetValue MFDataTypeLookup, 153
'Change Workflow State property in the PropertyValues collection to 1013
PropertyValues.SearchForProperty(39).TypedValue.SetValue MFDataTypeLookup, 1013
' Set the properties back to the object
Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, PropertyValues
Here is a script that works in an event handler. The last bit about changing the class is not relevant in most cases. There were special circumstances that required this operation in this particular case.
Perhaps the trouble with your script is that the workflow and state properties are not present on the object from the beginning. You can see below how I add those property definitions and then place a value in them.
'Eventhandler script to apply OCR workflow when property OCR Needed? = Yes (select from value list) 'To be placed in BeforeCheckInCanges '2021.03.19 Karl Lausten '2021.07.11 amended to change Class to "Other document" to be able to avoid Smart Classifier training at this point. Option Explicit ' Only run on Document type. if ObjVer.Type = MFBuiltInObjectTypeDocument Then Dim oPropVals : Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True ) Dim iCLrunOCR : iCLrunOCR = Vault.ClassOperations.GetObjectClassIDbyAlias("CL.Document") 'only run if Class is right if oPropVals.SearchForProperty(100).TypedValue.GetValueAsLookup.Item=iCLrunOCR then Dim iPDNeedOCR : iPDNeedOCR = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.NeedOcr") 'only run if Need OCR is Yes (1) if oPropVals.SearchForProperty(iPDNeedOCR).TypedValue.GetValueAsLookup().Item = 1 then 'Set the workflow to RunOcr Dim iWFocr : iWFocr = Vault.WorkflowOperations.GetWorkflowIDByAlias("WF.RunOcr") Dim WFProperty : set WFProperty = CreateObject("MFilesAPI.PropertyValue") WFProperty.PropertyDef = 38 'Builtin Workflow Property WFProperty.TypedValue.SetValue MFDatatypeLookup, iWFocr oPropVals.add -1, WFProperty 'Set the workflow state to Pause Dim iWFState : iWFState = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("WFS.RunOcr.Pause") Dim WFSProperty : set WFSProperty = CreateObject("MFilesAPI.PropertyValue") WFSProperty.PropertyDef = 39 'Builtin Workflow State Property WFSProperty.TypedValue.SetValue MFDatatypeLookup, iWFState oPropVals.add -1, WFSProperty 'Set the trigger valuelist to done (2) oPropVals.SearchForProperty(iPDNeedOCR).TypedValue.SetValue MFDatatypeLookup, 2 'Change class to "Other Document"(1) oPropVals.SearchForProperty(100).TypedValue.SetValue MFDatatypeLookup, 1 ' Save settings to object Vault.ObjectPropertyOperations.SetAllProperties ObjVer, true, oPropVals End if End if End if
Hello, thanks a lot it works, not directly from importing content replication but I added a property and launched recalculate option then Workflow and step are there !
© 2023 M-Files Inc. All rights reserved.