Dear M-Files Community,
I had a problem with one of my scripts when trying to set a MultiSelectLookup based on a search condition.
Basicaly, I was always having this Error Message : The value "XX-YY" does not exist, or it is a conflict object (LINE 74)
After looking for this error, I found a few posts that had the same problem:
- https://community.m-files.com/forums-1552881334/f/m-files-api/4191/error-the-value-105-0-does-not-exist-or-it-is-a-conflict-object
- https://community.m-files.com/forums-1552881334/f/m-files-api/5317/move-a-document-from-a-worflow-state-to-another-workflow-state-depending-of-a-property-value/13482#13482
- https://community.m-files.com/forums-1552881334/f/m-files-clients/4058/error-message-when-updating-metadata-card
The main issue is when setting up the lookup.item, you need to set it with the ObjVer.ID and not with the item(x).DisplayID
Please find down below the code so you might better understand what the problem was
dim MailTypeProperty : MailTypeProperty = 1205
dim ChantierProperty : ChantierProperty = 1075
dim EngineProperty : EngineProperty = 1196
dim DestinatairesProperty : DestinatairesProperty = 1420
dim technicienprop : technicienprop = 1160
'Fournisseur
Dim FournisseurProperty : FournisseurProperty = 1042
Dim FournisseursProperty : FournisseursProperty = 1023
Dim FournisseurObjectID : FournisseurObjectID =102
Dim FournisseurEmail : FournisseurEmail = 1135
Dim FournisseurRef
Dim MailTitle
Dim MailBody
dim DocType : DocType = PropertyValues.SearchForProperty(MailTypeProperty).TypedValue.DisplayValue
dim DestinatairesProp : set DestinatairesProp = PropertyValues.SearchForProperty(DestinatairesProperty)
dim DestinatairesLookups : set DestinatairesLookups = DestinatairesProp.TypedValue.GetValueAsLookups()
dim ChantierPropValue : set ChantierPropValue = PropertyValues.SearchForPropertyEx(ChantierProperty, true)
dim EnginePropValue : set EnginePropValue = PropertyValues.SearchForPropertyEx(EngineProperty, true)
dim technicienvalue : technicienvalue = PropertyValues.SearchForPropertyEx(technicienprop,true)
if not(technicienvalue is nothing or IsNull(technicienvalue.displayvalue)) then
'Create a reusable search condition to create Conditions to add to a Condition set
'Purpose is to search for documents with same suppliers and invoice numbers to get duplicatas
Dim Condition : Set Condition = CreateObject("MFilesAPI.SearchCondition")
'Create a search conditions set
Dim ConditionSet : Set ConditionSet = CreateObject("MFilesAPI.SearchConditions")
'Create condition : Non deleted objects
Condition.ConditionType = MFConditionTypeEqual
Condition.Expression.DataStatusValueType = MFStatusTypeDeleted
Condition.TypedValue.SetValue MFDatatypeBoolean, False
ConditionSet.Add -1, Condition
'Create condition : Employés object only
Condition.ConditionType = MFConditionTypeEqual
Condition.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
Condition.TypedValue.SetValue MFDatatypeLookup, 142 ' Employés
ConditionSet.Add -1, Condition
'Create condition : Employé only
Condition.ConditionType = MFConditionTypeEqual
Condition.Expression.DataPropertyValuePropertyDef = 100 ' Classe
Condition.TypedValue.SetValue MFDatatypeLookup, 63 'Projet
ConditionSet.Add -1, Condition
'Search by full name
Condition.ConditionType = MFConditionTypeEqual
Condition.Expression.DataPropertyValuePropertyDef = 1277 ' nom complet employé
Condition.TypedValue.SetValue 1, technicienvalue.displayvalue ' 1 = MFDatatypeText
ConditionSet.Add -1, Condition
Dim foundEmployee : Set foundEmployee = Vault.ObjectSearchOperations.SearchForObjectsByConditions(ConditionSet, MFSearchFlagNone, False)
if foundEmployee.Count > 0 then
dim i
Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
oLookup.Item = foundEmployee.Item(1).ObjVer.ID
oLookup.ObjectType = 142
oLookup.Version = -1
oLookup.ItemGUID = foundEmployee.Item(1).ObjectGUID
For i=1 To DestinatairesLookups.Count
if(DestinatairesLookups.Item(1).DisplayValue = technicienvalue.displayvalue) then
Err.Raise MFScriptCancel, "Le destinataire mentionné sera repris automatiquement depuis le CDC, merci de le retirer !"
end if
next
DestinatairesLookups.Add -1, oLookup
End If
end if
DestinatairesProp.TypedValue.SetValueToMultiSelectLookup DestinatairesLookups
Vault.ObjectPropertyOperations.SetProperty ObjVer, DestinatairesProp
