Version history not loading in backend after clearing some of them through api
Hi All,
I am working with sitefinity 9.2.I am using sitefinity api to remove old version history associated to my dynamic module. But after clearing some history by running the api, I noticed that the history is not loading. I have found a console error as shown below.
Failed to load resource: the server responded with a status of 500 (No row for Telerik.Sitefinity.Versioning.Model.Change ('sf_version_chnges') GenericOID@c758e83c Change id=8f67af2c-5814-6fe3-ae8a-ff0300fcd525 NOTRES)
Sharing the code I am using. Can somebody faced this before. Please help me to solve this.
public bool DeleteAllButASpecificNumberOfRevisionHistories(string moduleType, int revisionsToRemain)
var currentUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
Type dynamicType = TypeResolutionService.ResolveType(Constants.DynamicModuleCommon.ModuleTypeBase + moduleType);
foreach (var language in languages)
System.Threading.Thread.CurrentThread.CurrentUICulture = language;
var dynamicItems = DynamicModuleManager.GetDataItems(dynamicType).Where
(item => item.Status == ContentLifecycleStatus.Master).OrderByDescending(item => item.PublicationDate);
var versionManager = VersionManager.GetManager();
foreach (var item in dynamicItems)
// Get the version manager
// Get the changes for the news item
var changes = versionManager.GetItemVersionHistory(item.Id);
// Order the changes by version number and Skip by the
// amount you wish to remain in the Version History
var changeToRemove = changes
.OrderByDescending(c => c.Version)
.Skip(revisionsToRemain)
.FirstOrDefault();
// Check if a change is found that satisfies the filtering conditions
if (changeToRemove != null)
// Delete all changes with version number smaller or equal to the specified number
versionManager.TruncateVersions(item.Id, changeToRemove.Version);
if (DynamicModuleManager.HasChildItems(item))
var childversionManager = VersionManager.GetManager();
var dynamicChildItems = DynamicModuleManager.GetChildItemsHierarchy(item).Where(citem => citem.Status == ContentLifecycleStatus.Master);
foreach (var child in dynamicChildItems)
var transaction = child.GetType().FullName.Replace(Constants.DynamicModuleCommon.ModuleTypeBase, "");
var childChanges = childversionManager.GetItemVersionHistory(child.Id);
// Order the changes by version number and Skip by the
// amount you wish to remain in the Version History
var childChangeToRemove = childChanges
.OrderByDescending(c => c.Version)
.Skip(revisionsToRemain)
.FirstOrDefault();
// Check if a change is found that satisfies the filtering conditions
if (childChangeToRemove != null)
// Delete all changes with version number smaller or equal to the specified number
childversionManager.TruncateVersions(child.Id, childChangeToRemove.Version);
// Save the changes not inside loop
//versionManager.SaveChanges();
childversionManager.SaveChanges();
versionManager.SaveChanges();
System.Threading.Thread.CurrentThread.CurrentUICulture = currentUICulture;
Regards
Ajai