Hi all,
I've managed to return to the issue. I am sorry for the delay. Hope my comments might be still helpful.
The custom workflow handling can be quite tricky. I've been able to reproduce the situation that after new version is being edited, then checked in and button "publish" is hit, this version is published (and version pushed to major number x.0) but the new one with the handler-made changes is created and stays not published.
The aim here is that you don't want this new version to be created, but changes to the major (published) one only, if I'm right...
Since you use the code in the OnAfterPublish event, after using the CheckOut/ CheckIn, the document is pushed back to the edit state, with the new version created. This behavior is correct. Another thing is that the handler method accepts the reference to the TreeNode object and if you use DocumentHelper.GetDocument and pass its result to a different named variable, the reference is lost.
The optimal approach is to place your code in the OnBeforePublish and just retype the treeNodeObj object and directly set the node field values using SetValue and finally call UpdateDocument method.
I've managed to get this working, however there is still some catch I'm fighting with. The document on the live site is shown correctly, however the form tab shows the document data before the handler intervention, so does the version history view.
Please see the sample code below (based on your code, just used default fields):
public override void OnBeforePublish(object treeNodeObj, object tree)
{
// retype the treeNodeObj and treeprovider
TreeNode treeNode = (TreeNode)treeNodeObj;
TreeProvider treeprovider = (TreeProvider)tree;
treeprovider.UseCustomHandlers = false;
// [update node detail]
//Replace ` with ' for the headline ` would break the document alaise
if (treeNode.GetValue("ArticleName") != null)
{
string headline = treeNode.GetValue("ArticleName").ToString();
if (headline.Contains("`")) treeNode.SetValue("ArticleName", headline.Replace('`', '\''));
string body = "This is the teaser text of the article " + treeNode.GetValue("ArticleTeaserText").ToString();
treeNode.SetValue("ArticleTeaserText", body);
}
// documenthelper.updatedocument
DocumentHelper.UpdateDocument(treeNode, treeprovider);
}
That should be all, however I'm yet to resolve the issue with the version history not properly updated.
Regards,
Zdenek