Can't set property of checkout objVer

Hello everybody,

I am trying to update a property with the following code: 

      [... lookups is initialized ...]

        propertyValueNew.Value.SetValueToMultiSelectLookup(lookups);

        var lastObjVer  =  dashboard.Vault.ObjectOperations.GetLatestObjVer(objVer.ObjID,false,true);
        if(!dashboard.Vault.ObjectOperations.IsObjectCheckedOut(lastObjVer.ObjID,false)){
            dashboard.Vault.ObjectOperations.CheckOut(lastObjVer.ObjID);
        }
       dashboard.Vault.ObjectPropertyOperations.SetProperty(lastObjVer, propertyValueNew);  <= error on this line
        dashboard.Vault.ObjectOperations.CheckIn(lastObjVer.ObjID);
when I execute this code, I get : 
" CustomControlSite.cpp, 1051, L'objet est verrouillé dans M-Files, mais la version à laquelle vous tentez d'accéder n'est pas la version actuellement verrouillée. Ceci est peut-être dû à des données non réactualisées sur le client M-Files. Veuillez rafraîchir l'écran. (0x8004002D) "
That means I am trying to update a non checkout objet. How? I don't understand
Thanks
  • It could be the "lastObjVer" that plays tricks on you. It seems to represent the last checked in objVer, and you need to add 1 to its value to get the currently checked out ObjVer. The system creates a new ObjVer when the object is checked out by your process.

  • I'm sorry but I don't understand your answer. 

    Should I stop using the method GetLatestObjVer ?

  • No, the method is fine. My point was that the result in some cases will be the latest version checked in on the server - let's say it is version 5. When you check out the object in order to manipulate it, version 6 is created. If you still attempt to change version 5, you will get an error. With LastObjVer you have an option AllowCheckedOut which in your case has been set to False. Changing it to True may solve the problem. I have sometimes had to save the latest version in a variable and then add 1 before I could use the result for my purpose.

  • the right code was 

            propertyValueNew.Value.SetValueToMultiSelectLookup(lookups);

            var lastObjVer  =  dashboard.Vault.ObjectOperations.GetLatestObjVer(objVer.ObjID,true,true);
            if(!dashboard.Vault.ObjectOperations.IsObjectCheckedOut(lastObjVer.ObjID,true)){
                lastObjVer = dashboard.Vault.ObjectOperations.CheckOut(lastObjVer.ObjID).ObjVer;
                //lastObjVer  =  dashboard.Vault.ObjectOperations.GetLatestObjVer(objVer.ObjID,true,true);
            }
            dashboard.Vault.ObjectPropertyOperations.SetProperty(lastObjVer, propertyValueNew);
            dashboard.Vault.ObjectOperations.CheckIn(lastObjVer);
    Thank you