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

VBscript - getting the wrong object from GetLatestObjectVersionAndProperties(oObjID, True)

Hi guys!

I want to create a VBscript on a workflow transition to allow or disallow an automatic workflow transition. I've been looking for resources in the forum and got some things done however for some time now I'm stuck. In the function I want to get an object by id and then read a property value from it. After I've done this for some objects I want to compare the values and if the two values are the same I want to allow the transition for the state transition script runs on.

The problem I have is that Set oResult = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjID, True) returns the wrong object and I'm not sure where I'm going wrong.

Am I giving the wrong ID to the oObjID wich leads to GetLatestObjectVersionAndProperties loading the wrong object? When i look at the IDs they are the correct Display IDs.

What could I do better?

Here is the complete script

' *******************************************************************************************
' Check if Antragsteller.Vorgesetzer is equal to Antragsteller.Bereich(e).Führendes GL-Mitglied
' Konfiguration über M-Files GUI nicht möglich, da ansonsten ein Loop gemeldet wird
' *******************************************************************************************

'GET The IDs of the properties and ObjectType
Dim PropIdFGLMitglied, PropIdVorgesetzter, PropIdAntragsteller, PropIdBereich, ObjTypeIDBereich, ObjTypeIDMitarbeiter, ObjIDAntragsteller, ObjIDFuhrendesGLMitglied, ObjIDVorgesetzer
PropIdFGLMitglied = GetPropID("prop.FhrendesGlMitglied")
PropIdVorgesetzter = GetPropID("prop.Vorgesetzter")
PropIdAntragsteller = GetPropID("prop.Antragstellerinnen")
PropIdBereich = GetPropID("prop.Bereiche")
ObjTypeIDBereich = GetObjectTypID("objecttype.Bereich")
ObjTypeIDMitarbeiter = GetObjectTypID("objecttype.Mitarbeiterin")

'GET ObjectID of the Mitarbeiter referenced in Antragsteller --> Try lower one if top is not working
ObjIDAntragsteller = PropertyValues.SearchForProperty(PropIdAntragsteller).TypedValue.GetValueAsLookups().Item(1).DisplayID


ObjIDVorgesetzer = GetReferencedObjectID(ObjTypeIDMitarbeiter, ObjIDAntragsteller, PropIdVorgesetzter)
ObjIDBereich = GetReferencedObjectID(ObjTypeIDBereich, ObjIDAntragsteller, PropIdBereich)
ObjIDFuhrendesGLMitglied = GetReferencedObjectID(ObjTypeIDMitarbeiter, ObjIDBereich, PropIdFGLMitglied)


If cInt(ObjIDFuhrendesGLMitglied) = cInt(ObjIDVorgesetzer) Then
    AllowStateTransition = True
End If





'######Common Functions#####
Public Function GetPropID( alias )
    GetPropID = Vault.PropertyDefOperations.GetPropertyDefIDByAlias( alias )
End Function

Public Function GetObjectTypID(alias)
    GetObjectTypID = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias(alias)
End Function

'--------------------------------------------------------------------------------------------------------

Public Function GetReferencedObjectID(idObjectType, idObjectID, idPropertyID)
    ' Create a new ObjID object
    Dim oObjID : Set oObjID = CreateObject("MFilesAPI.ObjID")
	Call oObjID.SetIDs(idObjectType, CInt(idObjectID)) ' Sets the object type and ID

    
   

    ' Invoke the search operation
    Dim oResult
    Set oResult = Vault.ObjectOperations.GetLatestObjectVersionAndProperties(oObjID, True)

    Output =("ObjIDVorgesetzer: " + CStr(ObjIDVorgesetzer) + ", Type:  " + CStr(VarType(ObjIDVorgesetzer)) + " | ObjIDAntragsteller: " + CStr(ObjIDAntragsteller) + ", Type:  " + CStr(VarType(ObjIDAntragsteller)) + " | oResult: " + CStr(oResult.ToJSON()))


    ' Process the result
    If oResult Is Nothing Then
        Output = "Bases Object Not found" ' Or some other appropriate return value
    Else
           ' Assuming the property value is found and is a lookup
        GetReferencedObjectID = oResult.Properties.SearchForProperty(idPropertyID).TypedValue.GetValueAsLookups().Item(1).DisplayID
    End If
End Function

 

Parents Reply Children
No Data