Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler View modes: 
User avatar
Member
Member
seanbun-gmail - 7/21/2009 12:20:08 AM
   
Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi,

Below is m scenario:

1. Enabled Workflow on Node A and created child node under Node A.

2. Created a function on CustomEventHandler - OnAfterUpdate() to carry on validation and correction on the value of the field on all child node under Node A.

3. I used DocumentHelp class to get (.GetDocument) the node and update (.UpdateDocument) the node.

Problem

When I updated any child node under Node A, I went to the version property tab and found 2 new versions created.
i. the changes I made in CMSDesk e.g. v0.1
ii. the changes made by the CustomEventHandler v0.2

However, if I went back to the CMSDesk and the Form page of the child node, it did not display v0.2 but only v0.1. I could not see the changes made by the CustomeEventHandler.

Please advise.

Cheers,
Matt

User avatar
Member
Member
seanbun-gmail - 7/22/2009 12:29:19 AM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Is it possible to show us more details on the version table and its relationship to the document in the database? How would the CMSDesk pick the right version to display?

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 7/31/2009 2:39:19 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi,

some info can be found in DevGuide - API / Versioning internals

For updating versioned documents, you should use approach described in Updating a versioned document

I could anyway try to go into some more details ...I'll try to get back with the info.

Regards,
Zdenek C.

User avatar
Member
Member
seanbun-gmail - 7/31/2009 7:23:54 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Thanks for you reply.

Actually, I read the doc a couple of times and followed the approach to update the docment with DocumentHelper class. However, I still got the same problem.

That will be good if you can give me more details.

Cheers,
matt

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 8/6/2009 11:36:29 AM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi,

regarding the problem with versions (not) displayed in Form tab: According to the description it seems your code might do something wrong. Could you please write us:

- the code of the CustomTreeNodeHandler OnAfterUpdate method
- if you use CheckIn/CheckOut for documents
- how is your workflow configured, i.e. if it's default Edit-Publish-Archive or what other steps you use.

Thank you.

Regards,
Zdenek C.

User avatar
Member
Member
seanbun-gmail - 8/31/2009 11:43:13 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi Zdenek,

Thanks for you reply. Now I changed my code and the situation is slight different.

When I create an Article document, a "Taggedbody" field is created dynamically in the OnAfterPublish event as the code below. And following scenario happpen.
1. Article node successfully created on the tree in the CMSDesk
2. Node show in "published" status under workflow
3. Issue: "Taggedbody" field is empty in the mycustom_article table and View_mycustome_article and it does not show in the actual webpage(a page with a repeater/transformation to display the "taggedbody").
4. Issue: In the NodeXML field under dbo.CMS_VersionHistory table, Taggedbody could not be found.

Below is my workflow settings and code in the CustomEventHandler. Please advise.


Workflow settings
Edit -> Wait for approval -> Publish -> Archive

Below is the Code in the CustomEventHandler - OnAfterPublish Event


TreeNode treeNode = (TreeNode)treeNodeObj;
TreeProvider treeprovider = (TreeProvider)tree;

treeprovider.UseCustomHandlers = false;
treeNode = DocumentHelper.GetDocument(treeNode, treeprovider);

//Replace ` with ' for the headline ` would break the document alaise
if (treeNode.GetValue("Headline") != null)
{
string headline = treeNode.GetValue("Headline").ToString();
if (headline.Contains("`")) treeNode.SetValue("Headline", headline.Replace('`', '\''));
}

//Update keywords into links in the body
string body = Tagging(treeNode.GetValue("Body").ToString());
treeNode.SetValue("Taggedbody", body);

DocumentHelper.UpdateDocument(treeNode, treeprovider);


Cheers,
Matt

User avatar
Member
Member
RobV8R - 9/11/2009 2:50:56 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Matt,

Were you able to find a solution to this issue? We're running into the same thing.

Thanks,
Rob

User avatar
Member
Member
RobV8R - 9/11/2009 2:51:00 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Matt,

Were you able to find a solution to this issue? We're running into the same thing.

Thanks,
Rob

User avatar
Member
Member
seanbun - 9/11/2009 6:07:18 PM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hey Rob,

I found a solution/work-around to this yesterday.

If you look at my code in my previous post, I use DocumentHelper to get and update my treenode. User VersionManager to check-in the node before your get the treenode and checkout the node after update the node.

This would bring the treenode back to "Edit" workflow step. Therefore, you need to use workflowmanager to publish the treenode again. Let me know if this works to you.

Hey ZDenek,

Is this a bug? is it possible to update the document in the same version?

Cheers,
Matt
twitter: http://twitter.com/seanbun

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 9/24/2009 1:26:05 AM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi Sean,

thanks for the information.

It should be possible to update document without creating new version using method DocumentHelper.UpdateDocument(treeNode, treeprovider); where the document has to be checked in. The behavior in your previous post was observed in 4.0 version (default build or hotfix)?

I'm trying reproduce it and find out if the behavior is ok or not a bug.
To understand your workaround steps -- you perform following:

- ensure document is checked in (if not, use API to check it in)
- update document using above mentioned method
- checkout the node
- publish the node (using WorkflowManager)

Otherwise the custom field is not updated...? or the version that is later used by cms is not the one which has been updated? I don't understand if you later publish the document, why do you check it out...am I missing something?

Anyway I'll try to return back with any findings soon.

Regards,
Zdenek.

User avatar
Member
Member
seanbun - 10/2/2009 12:34:06 AM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
Hi Zdenek,

I worked on version 4.0. Sorry to confuse you and I provide wrong information on my previous post.

It should be the other way around. I used versionmanager to check-out the node after get the node with documenthelper method. Also check-in the node after update it. Below steps are executed in the CustomEventHandler(OnAfterPublish).

1. documenthelper.getdocument
2. check-out (versionmanager)
3. [update node detail]
4. documenthelper.updatedocument
5. check-in (versionmanager)

if I do not follow above procedures, the changes made by the CustomEventHandler coding (step 3) would not be picked up. In the NodeXML field under dbo.CMS_VersionHistory table, the changes could not be found either.

Cheers,
Matt

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 10/22/2009 6:23:04 AM
   
RE:Unable to load the latest content on CMSDesk - Workflow/DocumentHelper/CustomEventHandler
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