2

I am adding a new version of an item in a different language. This works fine. Them I am setting the field values on the new version, but those values are not saved. The code is basically (simplified):

Item englishItemVersion = _newDatabase.GetItem(swedishItem.ID, englishLanguage).Versions.AddVersion();
englishItemVersion.Editing.BeginEdit();
englishItemVersion.Fields[{guid}].Value = “my English title”;
englishItemVersion.Editing.EndEdit(false, true);

When i debug the code, all the fields on the new itemversion is set, but as soon as the code hits EndEdit(false, true);, all the values in the fields disappear. Why is that?

  • 1
    How do you know the values disappeared? Do you check for them in Content Editor? In other place in code? Directly in database? Are you sure your "_newDatabase" points to the master database? – Marek Musielak Dec 12 '16 at 10:39
  • 1
    I am watching the fields as i debug the code, line by line. And when i check in the content editor afterwards, there are no values either. And yes, the database reference works fine. The english item version is created even, but the fields are not set. – Troels Aaberg Dec 12 '16 at 10:57
  • 1
    May be worth trying to put your code inside "using (new Sitecore.SecurityModel.SecurityDisabler()){//your code}" ? – Dheeraj Palagiri Dec 12 '16 at 11:13
  • 2
    Try changing your .EndEdit() call to .EndEdit(true, false) or .EndEdit() without flags. – Mark Cassidy Dec 12 '16 at 11:17
  • @MarkCassidy That actually did the trick. Although i do not see how that should affect it, it indeed does work when i remove those flags. Thanks for the idea. – Troels Aaberg Dec 12 '16 at 11:53
2

So the problem was in the .EndEdit() call.

By calling .EndEdit(false, true) you are essentially telling Sitecore two things:

  1. Do not update revision, revision date and so on. In other words, try and "hide" that the update took place
  2. Disable events for this update

So basically you did pretty much everything you could, to try and hide the fact that you were adding versions and adding fields, to your surroundings. Including Content Editor, which would then not get notified that item changes took place. Caches would not get invalidated. And so on.

  • The code is to be used in a migration, where i do not care that caches etc is not updated. I just want to migrate and manipulate 100k items as fast as possible. It was my understanding that disabling events and diabling statistics would help that. But if i cant add language versions ,then that does not help at all. I am having a look at EventDisabler and BulkUpdateContext instead now. – Troels Aaberg Dec 13 '16 at 11:56
  • Are you running a non-up-to-date Unicorn by any chance? – Mark Cassidy Dec 13 '16 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.