Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home

Copy date in workflow using script

Last updated on 28 September 2021

Calculated Property Values

Overview

Please notice that scripting is not a part of standard support and this is just an example script to show how to use the API. Be aware that all scripts are run at your own risk.
Copying a property value on the M-Files metadata card in another property from a particular point of time may be useful when the source property is prone to change, and instead of checking version history it would be easier to show the information on the metadata card.
The following script can be used to get started. it is run in a workflow state action to capture the value of a date property (from sourcedate property to targetdate).

Solution


Option Explicit
Dim iPDSourceDate : iPDSourceDate = GetPropertyIDByAlias("MF.PD.SourceDate")
Dim iPDTargetDate : iPDTargetDate = GetPropertyIDByAlias("MF.PD.TargetDate")
Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer, False)

If PropertyValues.IndexOf(iPDSourceDate) <> -1 and PropertyValues.IndexOf(iPDTargetDate) <> -1 Then
                             Dim txtSourceDate : txtSourceDate = PropertyValues.SearchForProperty(iPDSourceDate).TypedValue.DisplayValue
                             Dim iDataType : iDataType = Vault.PropertyDefOperations.GetPropertyDef(iPDTargetDate).DataType
                             Dim newPropertyValue : Set newPropertyValue = CreateObject("MFilesAPI.PropertyValue")
                             newPropertyValue.PropertyDef = iPDTargetDate
                             newPropertyValue.TypedValue.SetValue MFDatatypeDate, txtSourceDate
                             Vault.ObjectPropertyOperations.SetProperty ObjVer, newPropertyValue
End If

Function GetPropertyIDByAlias(alias)
                             Dim iID
                             iID = Vault.PropertyDefOperations.GetPropertyDefIDByAlias(alias)
                             If iID = -1 Then
                                                          Err.Raise MFScriptCancel, "Property Definition not found in vault by specified alias of '" & alias & "'"
                             End If
                             GetPropertyIDByAlias = iID
End Function
 

Still need help?

On this page