HI,
I am not a developper, but I tried to run a vb script code to search for a specific opbjet (type "produits finis") which has the (unique) metadata value ("matricule").
This metadata is deducted from the content of the file through regex which is OK.
The code is rising an error : "type incompatible : Expression.SetPropertyValueExpression". I can't find what is the right syntax I should use. (line 71)
Can someone help me?
Many thanks in advance
'Extract metadata from file content using regex.
'Suited for documents with a fixed content format and limited file size.
'2022.06.27 Karl Lausten
Option Explicit
Dim objID : set objID = ObjVer.ObjID
Dim objVersion : set objVersion = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(objID, true)
Dim myFiles : Set myFiles = objVersion.VersionData.Files
Dim myFile
Dim fileVer
For Each myFile in myFiles
set fileVer = myFile.FileVer
Next
'This script was made to run on single file objects. The script is not prepared to handle multiple files!
'Running it on documents with multiple files will create problems such as propertyvalues being overwritten in the proces below.
'on récupère le text intégral du fichier
Dim szFullText :szFullText = Vault.ObjectFileOperations.GetTextContentForFile(ObjVer, fileVer)
Dim oPattern : Set oPattern = New RegExp 'le pattern de la regex
'ici on récupère dans le texte le matricule
Dim oPropertyValue
Dim iMAT : iMAT = Vault.PropertyDefOperations.GetPropertyDefIDbyAlias("PD.Matricule") 'iMAT est l'ID de la propritété MAtricule
With oPattern
'.Pattern = "(\d{2}\-\d{2}\-\d{4})(?=\s*Dato:)"
.Pattern = "([A-Z]*[0-9]{3,4}[A-Z]{1,2}[0-9]{4,6})"
.IgnoreCase = True
.Global = True
End With
Dim szMatch : set szMatch = oPattern.Execute(szFullText)
'Err.Raise MFScriptCancel,szMatch.Item(0).SubMatches(0)
Set oPropertyValue = PropertyValues.SearchForProperty(iMAT)
oPropertyValue.TypedValue.SetValue MFDatatypeText, szMatch.Item(0).SubMatches(0)
Vault.ObjectPropertyOperations.SetProperty ObjVer,oPropertyValue
'ici on récupère dans l'objet du mail la couleur du toner
Dim NewPropertyValue
Dim iObjet_email : iObjet_email = Vault.PropertyDefOperations.GetPropertyDefIDbyAlias("PD.Objet")
Dim szObjet_email : szObjet_email=PropertyValues.SearchForProperty(iObjet_email).typedvalue.value
With oPattern
'.Pattern = "(\d{2}\-\d{2}\-\d{4})(?=\s*Dato:)"
.Pattern = "(.yan|.ellow|.aune|.oir|.agenta|.lack)"
.IgnoreCase = True
.Global = True
End With
set szMatch = oPattern.Execute(szObjet_email)
Set NewPropertyValue = PropertyValues.SearchForProperty(iObjet_email)
NewPropertyValue.TypedValue.SetValue MFDatatypeText, szMatch.Item(0).SubMatches(0)
Vault.ObjectPropertyOperations.SetProperty ObjVer,NewPropertyValue
''''''''''''''''' la suite ici permet d'aller cherche le copieur qui a ce matricule
Dim matriculecherche :matriculecherche = szMatch.Item(0).SubMatches(0)
' Initialize the API and connect to a vault.
' initialise une searchcondition et une search condition multiple
Dim FstSearchCondition : Set FstSearchCondition = CreateObject("MFilesAPI.SearchCondition")
Dim AllSearchConditions : Set AllSearchConditions = CreateObject("MFilesAPI.SearchConditions")
'FstSearchCondition.Expression.SetValueListItemExpression 2, 0, Nothing ' MFValueListItemPropertyDefName = 2, MFParentChildBehaviorNone = 0
''We want to search by property - in this case the built-in "name or title" property.
''Alternatively we could pass the ID of the property definition if it's not built-in.
FstSearchCondition.Expression.SetPropertyValueExpression 1308, 0
'' We want only items that equal the search string provided.
FstSearchCondition.ConditionType = MFConditionTypeEqual
'' Note that the type must both match the property definition type, and be applicable for the supplied value.
FstSearchCondition.TypedValue.SetValue MFDatatypeText, matriculecherche
AllSearchConditions.Add -1, oSearchCondition
'' Create the seconde condition.
Dim SdSearchCondition : Set FstSearchCondition = CreateObject("MFilesAPI.SearchCondition")
'' Set the expression.
SdSearchCondition.Expression.SetStatusValueExpression MFStatusTypeObjectTypeID
'' Set the condition.
SdSearchCondition.ConditionType = MFConditionTypeEqual
'' Set the value.
SdSearchCondition.TypedValue.SetValue MFDatatypeLookup, 194 'OBJET produit fini ID (194)
'' Add the condition to the collection.
AllSearchConditions.Add -1, SdSearchCondition
' Invoke the search operation.
Dim oSearchResults : Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditionsEx (AllSearchConditions)
Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)
' Simply process the search results.
'For Each oObjectVersion As MFilesAPI.ObjectVersion In oObjectVersions
' Resolve the object type.
'Dim oObjType As MFilesAPI.ObjType
' oObjType = oVault.ObjectTypeOperations.GetObjectType(oObjectVersion.ObjVer.Type)
' Output the result.
' Call Console.WriteLine("Title of " + oObjType.NameSingular + ": " + oObjectVersion.Title)
'Next
