Accesing variable form reference object VB Script

Hey, I'm triyng to access a property that is in chose from list Object. Im getting "Object required: '1' ". as an error.  Thank you in advance for your help. 

Option Explicit

Dim postavke
postavke = PropertyValues.SearchForProperty(1283).TypedValue.GetValueAsLookup.Item

Dim uvjet : uvjet = Vault.ObjectPropertyOperations.GetProperties( postavke.ToObjVer(), True )
                                                                                                                     

If uvjet.SearchForProperty(1282).TypedValue.DisplayValue = "Yes" Then
    AllowStateTransition = True
Else
    AllowStateTransition = False
End If

Parents
  • Try this:

    Option Explicit
    
    Dim postavke
    set postavke = PropertyValues.SearchForProperty(1283).TypedValue.GetValueAsLookup().GetAsObjVer
    
    Dim uvjet : set uvjet = Vault.ObjectPropertyOperations.GetProperties( postavke, True )
                                                                                                                         
    
    If uvjet.SearchForProperty(1282).TypedValue.DisplayValue = "Yes" Then
        AllowStateTransition = True
    Else
        AllowStateTransition = False
    End If

    When you get an error you need to look carefully in the full error description. You will be able to find which line in your code creates the error. That is quite helpful in debugging - especially if you combine it with careful use of the API documentation https://developer.m-files.com/APIs/COM-API/Reference/

  • DocumentCache.cpp, 7599, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    DocumentCache.cpp, 19402, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCMethodCallWithRetry.h, 27, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCMethodCallWithRetry.h, 27, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperations.cpp, 11362, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperations.cpp, 5540, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    MCallInLoop.h, 521, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 1995, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 212, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 9630, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 10831, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 11087, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 25849, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 25979, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 9647, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 11087, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 25791, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    StateTransitionManager.cpp, 263, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    StateTransitionManager.cpp, 1050, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 275, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Script execution failed. ((State transition (ID: 153), StateTransitionValidation: 36-2)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 340, Not found. (ID: 1) (0x8004000B)
    VaultScriptSessionTemplates.cpp, 523, Not found. (ID: 1) (0x8004000B)
    CoActiveScriptSite.cpp, 897, Not found. (ID: 1) (0x8004000B)
    CoActiveScriptSite.cpp, 739, Not found. (ID: 1) (0x8004000B)
    State transition (ID: 153), StateTransitionValidation, 6, Not found. (ID: 1) (0x8004000B)
    MNullPropagatingDispatchImpl.h, 127, Not found. (ID: 1) (0x8004000B)
    MNullPropagatingDispatchImpl.h, 174, Not found. (ID: 1) (0x8004000B)
    CoVaultObjectPropertyOperations.cpp, 345, Not found. (ID: 1) (0x8004000B)
    ServerVaultObjectPropertyOperationsHelper.cpp, 77, Not found. (ID: 1) (0x8004000B)
    RPCObjectOperationsHelper.cpp, 34, Not found. (ID: 1) (0x8004000B)
    CoRPCOverCOM.cpp, 6935, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperations.cpp, 6382, Not found. (ID: 1) (0x8004000B)
    MCallInLoop.h, 521, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelper.cpp, 5800, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelper.cpp, 5838, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelper.cpp, 14356, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelper.cpp, 14584, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelperPrivate.cpp, 12559, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelper.cpp, 28811, Not found. (ID: 1) (0x8004000B)
    RPCDocumentOperationsHelperPrivate.cpp, 11476, Not found. (ID: 1) (0x8004000B)
    (M-Files 23.9.12966.6 2023-11-02T06:36:26.710Z)

  • Note this line:
    State transition (ID: 153), StateTransitionValidation, 6, Not found. (ID: 1) (0x8004000B)

    The error origins from line 6 in the code.
    "Not found" probably means that the variable "postavke" did not provide the required input. So, you need to go back to line 4 and figure out what is wrong there.
    It could be that a simple "()" is needed after GetAsObjver as suggest in the documentation.
    It could also be that property 1283 is not a single select lookup property, or that the property is empty on the current object. I can't tell from the info available here, that is something you need to work on.


  • Option Explicit
    
    Dim postavke
    set postavke = PropertyValues.SearchForProperty(1283).TypedValue.GetValueAsLookup().GetAsObjVer()
    
    Dim uvjet : set uvjet = Vault.ObjectPropertyOperations.GetProperties( postavke, True )
                                                                                                                         
    
    If uvjet.SearchForProperty(1282).TypedValue.DisplayValue = "Yes" Then
        AllowStateTransition = True
    Else
        AllowStateTransition = False
    End If

    To me it all checks out. Only the code could be the issue. I belive the objVer "Postavke" is taken I beleve so because it is searching for ID 1 but when i use it to search property it points to no object type or wrong one so it gets "not forund".

    I have tested it by using 

    Dim OV : set OV = Vault.ObjectOperations.GetLatestObjVer( postavke.objID, false, false )
    So problem is with ObjVer that i get from Postavke its missing something.

    working code looks like 

    Option Explicit
    
    Dim postavke
    set postavke = PropertyValues.SearchForProperty(1283).TypedValue.GetValueAsLookup().GetAsObjVer()
    
    Dim OV : set OV = Vault.ObjectOperations.GetLatestObjVer( postavke.objID, false, false )
    
    Dim uvjet : set uvjet = Vault.ObjectPropertyOperations.GetProperties( OV, True )
                                                                                                                         
    
    If uvjet.SearchForProperty(1282).TypedValue.DisplayValue = "Yes" Then
        AllowStateTransition = True
    Else
        AllowStateTransition = False
    End If

  • I belive this is a bug. Where do i report something like that?

  • I do not agree that this is a bug.
    The problem is perhaps that you set True as the last variable in line 6
    Dim uvjet : set uvjet = Vault.ObjectPropertyOperations.GetProperties( postavke, True )
    This forces the code to check the properties from the server. If the object has not been checked in at this point there will be no properties to find on the server. Try setting it to False in stead.

  • Dealing with a similar task, I found this thread.

    I think it is a bug.

    GetAsObjVer() returns for the version field "-1",
    while
    GetLatestObjVer returns for the version field "1" (or another positive integers).

    The "-1" value called from outside (e.g. EXCEL) causes no error.

    The VBScript code plugged into M-Files gives the "No found." error.

    I hope, somebody reads this after 11 months and, maybe, it is helpful for somebody struggling at a similar issue.

    I could not find any related documentation. Best regards. Holger

  • -1 is a default value for "latest version"
    This is not a bug but an important build in function that allows the system to always get the latest version of an object no matter whether that is version 1 or version 101.
    When dealing with versions i scripts or VAF it is often necessary to specifiy a specific version. This can be tricky when you check out an object to manipulate it because the version increases by 1 in the moment you check it out. So you fetched version 1 from the server, but you are manipulating version 2.

  • I did not argue about the feature of "-1". The original post described an error message "Not Found.", when referring to an object version retrieved by GetAsObjVer.
    The methods of ObjectPropertyOperations should deal with the "-1" correctly, shouldn't they?

Reply Children
  • It is not my place to argue on behalf of M-Files. However, I think the methods work as they should. Depending on your intentions you sometimes just need to read values from an object without checking it out. In that case you get the correct version. Other times you need to manipulate data somehow and you check out the object and get a new version with an increased version number. Depending on your choice you need to handle the version number accordingly.

  • I wrote a long response to this yesterday but it looks like I lost it.  That's really unfortunate.

    The issue here is the fact you're converting from a Lookup to an ObjVer.

    A lookup is a pointer to another object in the system.  Most of these lookups are version-independent; they point to a particular object, not a particular object version.  Consider a common situation of a document pointing to a customer - the relationship is to the customer, not to a particular version of that customer.

    Version-specific lookups do exist.  If you look at the lookup class you'll see that it can contain a version.  These are useful in specific situations.  For example: consider a case where you provided a document to an auditor as part of an audit; in that case it's useful to know not only which document, but also which version of the document.

    So the "GetAsObjVer" method will literally take the data in the lookup - the object id, type, and version if there is one - and return it as that different structure.  If the lookup is version-independent then it will return -1 to show that.

    Unfortunately most of our API methods require you to provide the exact version of the object when performing actions such as retrieving properties.  The API methods do not unfortunately automatically convert -1 to the latest version.  This is by design; operations that take an ObjVer need the version data, but operations that take an ObjID do not.

    If you want to use GetAsObjVer, as an example, then you need to have some code that deals with the fact that the lookup may not return a version number.  If it does not then you have to go back to the server and ask for the latest version before you use it.

  • Thanks to both of you for the clarification. Maybe, your explanation can be included in the M-Files API manual.