Hi everyone, I'm trying to sync copied items that have been marked as "related", when the source document is published. I didn't find any way by which I can sync the values of two document objects so I tried deleting the target object, and creating a new object in it's place when the source is published.
void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) { if (sender.Relations.Length > 0 && sender.Level > 1) { foreach (Relation r in sender.Relations) { //if the sender is the parent in the relationship if (r.Parent.Id == sender.Id) { if (r.Child.Parent != null) { //delete the child node, and replace it with the new version CMSNode parent = r.Child.Parent; //error in the following statement r.Child.delete(); sender.Copy(parent.Id, sender.User, true); //somehow get the new node, and publish it } } } }
However, when I publish a document I get an error, The DELETE statement conflicted with the REFERENCE constraint
"FK_cmsContent_umbracoNode" when I callr.Child.delete(); Is there a nicer way of keeping related items in sync? I'm not too familiar with the relationship API, so any ideas/code samples would be great! Thanks.
Copying a document into related items on publish
Hi everyone, I'm trying to sync copied items that have been marked as "related", when the source document is published. I didn't find any way by which I can sync the values of two document objects so I tried deleting the target object, and creating a new object in it's place when the source is published.
However, when I publish a document I get an error, The DELETE statement conflicted with the REFERENCE constraint
"FK_cmsContent_umbracoNode" when I call r.Child.delete(); Is there a nicer way of keeping related items in sync? I'm not too familiar with the relationship API, so any ideas/code samples would be great! Thanks.
is working on a reply...