Rollback Object to some previous version?


I can roll back objects from condition search but I'd like modify current document in workflow, but it says that code is running or similar. How to modify this to run on workflow for current object? Reason why conditions is not an option is the number of objects to modify -> Timeouts

dim DocID, DocVer, VersionNum

Set DocID = Objver.objid
DocVer = Objver.Version
VersionNum = DocVer - 2

Dim CurVersion : Set CurVersion = Vault.ObjectOperations.GetLatestObjVer( DocID, True, True)

Vault.ObjectOperations.Checkout( DocID )

Vault.ObjectOperations.Rollback DocID, VersionNum

Vault.ObjectOperations.CheckIn( DocID )