Skip to main content
added an additional note
Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

So you set the title after making sure your Component is checked out, but you tried to sync back the changes of the content before ensuring it is checked out:

...
// sync content back to Component
newComp.Content = content.ToXml();
...
// sync metadata back to Component
newComp.Metadata = embeddedFields.ToXml();
...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Save(true);

Now if you would first check if your Component needs to be checked out before syncing back its content, then I think you will get a better result on your save. Because I expect that when you call newComp.CheckOut(); all your previous actions on newComp will be reset.

So change it into something like this:

...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Content = content.ToXml();
newComp.Metadata = embeddedFields.ToXml();
newComp.Save(true);

Note that the line if (newComp.IsCheckedOut) newComp.CheckIn(); after calling newComp.Save(true); might undo a "permanent" lock that was set on the Component. Although that might be intentional of course.

So you set the title after making sure your Component is checked out, but you tried to sync back the changes of the content before ensuring it is checked out:

...
// sync content back to Component
newComp.Content = content.ToXml();
...
// sync metadata back to Component
newComp.Metadata = embeddedFields.ToXml();
...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Save(true);

Now if you would first check if your Component needs to be checked out before syncing back its content, then I think you will get a better result on your save. Because I expect that when you call newComp.CheckOut(); all your previous actions on newComp will be reset.

So change it into something like this:

...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Content = content.ToXml();
newComp.Metadata = embeddedFields.ToXml();
newComp.Save(true);

So you set the title after making sure your Component is checked out, but you tried to sync back the changes of the content before ensuring it is checked out:

...
// sync content back to Component
newComp.Content = content.ToXml();
...
// sync metadata back to Component
newComp.Metadata = embeddedFields.ToXml();
...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Save(true);

Now if you would first check if your Component needs to be checked out before syncing back its content, then I think you will get a better result on your save. Because I expect that when you call newComp.CheckOut(); all your previous actions on newComp will be reset.

So change it into something like this:

...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Content = content.ToXml();
newComp.Metadata = embeddedFields.ToXml();
newComp.Save(true);

Note that the line if (newComp.IsCheckedOut) newComp.CheckIn(); after calling newComp.Save(true); might undo a "permanent" lock that was set on the Component. Although that might be intentional of course.

Source Link
Bart Koopman
  • 29.6k
  • 3
  • 40
  • 90

So you set the title after making sure your Component is checked out, but you tried to sync back the changes of the content before ensuring it is checked out:

...
// sync content back to Component
newComp.Content = content.ToXml();
...
// sync metadata back to Component
newComp.Metadata = embeddedFields.ToXml();
...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Save(true);

Now if you would first check if your Component needs to be checked out before syncing back its content, then I think you will get a better result on your save. Because I expect that when you call newComp.CheckOut(); all your previous actions on newComp will be reset.

So change it into something like this:

...
if (!newComp.IsCheckedOut)
{
    newComp.CheckOut();
}
newComp.Title = "TEST-" + DateTime.Now;
newComp.Content = content.ToXml();
newComp.Metadata = embeddedFields.ToXml();
newComp.Save(true);