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

Linking to a specific object version

oSRs is the result an object search that I perform.  I then output oSRs.item(1).objver.ID to a property but how do I output the current specfic version? Currently the entry in the property updates to the latest object version as its revised where as I would like it to refer to the current version at the time.

  • Try

    oSRs.item(1).objver.VersionEx.Version

    This should produce the specific version number.

  • Thank you for your response bright-ideas.dk.  Unfortunately, it isn't working. I am not sure why, but it seems to output a different document altogether when changing objver.ID to objver.versionex.version.

  • oSRs.item(1).objver.Version
    should give you the internal M-Files version number.

    Regards,

    Craig.

  • Thank you Craig. I have an automatic calculation on a property which searches for a document and the result is outputed like so: 

    output = oSRs.Item(1).ObjVer.ID

    Could you give me an idea as to how I change this to output the specific version please? 

  • Assuming your output is intended to go into a lookup property that selects objects of the document type you will need to create a lookup object with the object type, ID and version required. I did something similar a few years ago. Here is a copy of the code used (no guarantees!):

    ' Script to copy a set of "latest version" document references from Property A 
    ' to a set of version specific document references in Property B 
    ' choosing the current version at the time of calculation.
    ' This script must not be repeated (recalculated) because that might change the specific version,
    ' therefor it will not run if Property B already has values in it.
    ' 2018.11.21 Karl Lausten
    Option Explicit
    Dim iPDDocsSpecVers : iPDDocsSpecVers = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.RefDocsSpecVersion") 
    Dim oDocumentsInB: Set oDocumentsInB = PropertyValues.SearchForProperty(iPDDocsSpecVers)
    if not isNull (oDocumentsInB) then
    	'get a list of the documents in Property A
    	Dim iPDRefdByDocs : iPDRefdByDocs = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.ReferencedDocs") 
    	Dim oDocumentsInA: Set oDocumentsInA = PropertyValues.SearchForProperty(iPDRefdByDocs)
    	If not isNull(oDocumentsInA) then 
    		' Clone A
    		Dim oALookups: Set oALookups = oDocumentsInA.Value.GetValueAsLookups
    		Dim oBLookups: Set oBLookups = oALookups.Clone
    
    		Dim oDocumentLookup
    		Dim oObjID: set oObjID = CreateObject("MFilesAPI.ObjID")
    		Dim oDocumentObjVer, oDocumentVersionX
    		For Each oDocumentLookup In oBLookups
    			if not oDocumentLookup.Deleted = True then
    				oObjID.SetIDs 0, oDocumentLookup.Item
    				'err.raise MFScriptCancel, oObjID.Type & " , " & oObjID.ID
    				Set oDocumentObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
    				oDocumentVersionX = oDocumentObjver.VersionEx.Version
    				'err.raise MFScriptCancel, oDocumentVersionX
    				oDocumentLookup.Version = oDocumentVersionX ' Set to current version instead of -1
    			End if
    		Next
    
    		' Assuming Property B is Automatic Value
    		Output.SetValueToMultiSelectLookup oBLookups
    	End if
    End if

    You may need to change the code if the target property is single select.

  • Thank you so much! I have got this far: 

    Dim oSRs : Set oSRs = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSCs, MFSearchFlagLookInAllVersions, True)
    	If oSRs.Count > 0 then
    		Dim SourceDoc : Set SourceDoc = oSRs.item(1) 
    		Dim SourceDocObjVer : Set SourceDocObjVer = Vault.ObjectOperations.GetLatestObjVer(SourceDoc.objver.ObjID, False, False)
    		Dim SourceDocX: SourceDocX = SourceDocObjVer.VersionEx.Version
    		SourceDoc.ObjVer.version = SourceDocX 'Update the Product property
    		Output = SourceDoc.ObjVer.version
    	End If

    But the value of the calculated property is showing as (hidden). Do you have any idea why this might be?

  • Take another look at the code that was posted.  You are setting the output equal to the version.  The output is expecting an object reference, so it's assuming this version is an object ID.  You need to instead create a Lookup pointing to the object and version that you're interested in.

  • Thank you for your response. I have since got this to work executing on the property itself:

    If oSRs.Count > 0 then
    	Dim SourceDoc : Set SourceDoc = CreateObject("MFilesAPI.Lookup")
    	SourceDoc.item = oSRs.item(1).ObjVer.ID
    	SourceDoc.Version = oSRs.item(1).ObjVer.Version
    	Output = SourceDoc
    End If

    I am trying to move the code into a workflow and I am struggling with the following: 

    If oSRs.Count > 0 then
    	Dim SourceDoc : Set SourceDoc = CreateObject("MFilesAPI.Lookup")
    	SourceDoc.item = oSRs.item(1).ObjVer.ID
    	SourceDoc.Version = oSRs.item(1).ObjVer.Version
    	Dim PropVal
    	PropVal.PropertyDef = 1421
    	PropVal.TypedValue.SetValue MFDatatypeLookup, SourceDoc
    	Vault.ObjectPropertyOperations.SetProperty ObjVer, PropVal
    End If

    I keep getting a "Object required: ''" error though.  Could you advise please?

  • Looks like you declare "PropVal" but never set it to an instance of the object you want.  Did you mean to do this?

    Dim PropVal: Set PropVal = CreateObject("MFiles.PropertyValue")

  • I'm so sorry. Such a silly error. I've corrected that but its saying line 7 has a Type mismatch. Why was line 6 ok when the same value was being set on the property, which is a single select list property of documents, but it is a Type Mismatch when setting the values on a MFDatatypeLookup within a workflow?