Kentico Workflow CMSForm

Matt Swain asked on January 20, 2015 13:45

Hi Everyone,

I have a page which has a CMSForm object on the page which allows the end user to edit a document that they are assigned to (custom.Driver).

This works fine and the user can edit their document and their changes are reflected inside Kentico form tab.

However I have recently turned on the default Edit -> Published -> Archived workflow and even though it edits the document and it appears inside the CMS (And appears as published not edited), On the front end of the site it holds onto the old version of the document and for example displays the old name (even after clearing the cache).

Only if I go in and re-edit the document and then click on publish does it apppear on the front end of the site.

My question is how using the API do I make the latest version the version that the site listens to?

I have the following code on the onaftersave method of the CMSForm to find the document that has been edited.

TreeNodeDataSet tnds = TreeHelper.SelectNodes("/%", true, "custom.Custom", string.Format("DriverID = {0}", DriverID), "", -1, false); if (!DataHelper.DataSourceIsEmpty(tnds)) { TreeNode editingNode = tnds.FirstOrDefault();

// ON THIS EDITING NODE HERE THE NAME OF THE DOCUMENT IS 'DRIVER 1' which is the one that is currently live showing the old name.

// If I use documentHelper.GetDocument which always returns the latest document version then

                    editingNode = DocumentHelper.GetDocument(editingNode, new TreeProvider());

// ON THIS EDITING NODE HERE (THE LATEST ONE) THE NAME OF THE DOCUMENT IS (RIGHT) 'DRIVER 1 AFTER UPDATE' WHICH IS CORRECT.

The site (repeaters/list menus etc.) all show DRIVER 1 even after a clear of the cache.

Any Idea how I promote the latest version to be the one that it listens to? Even thought it's showing as published in the workflow step and inside Kentico CMS it still uses the old name in repeaters etc even after clearing the cache, the only way to get it to display is to go into Kentico change the document slightly and then click save and re-publish.

Any Help would be greatly appreciated.

Recent Answers


Brenden Kehren answered on January 20, 2015 13:54

The site will always take the last published version so when you save your node changes (insert or update), simply do node.Publish(); Or you can always push it through workflow to a specific step which involves a few more lines of code.

0 votesVote for this answer Mark as a Correct answer

Matt Swain answered on January 20, 2015 13:57

Hi Brenden,

Thanks for your answer.

I thought this also - so I did just that and did editingNode.Publish() but it didn't do make any difference. I assume because it is already in the Published Workflow Step it just get ignores.

Thanks,

Matt

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on January 20, 2015 14:02

If a document is in Publish step, you make a change, save it, and publish it, that counts as a new version. By default, it will run it through workflow again, place it in the edit step and your Publish() will create a new version. Have you looked at the version history? What does it show?

0 votesVote for this answer Mark as a Correct answer

Matt Swain answered on January 20, 2015 14:07

Hi Brenden,

I am using a CMSForm web part to allow the end user to update a custom document within the tree. If I go to the CMSDesk then it just shows the one version in the version history of the document. If I edit the document again inside CMSDesk (even though it is showing as right and published) and then do a re-publish it works and a second version is created.

Even if on the onaftersave I find the latest version of the document (as above) and run the publish method.

Thanks,

Matt

0 votesVote for this answer Mark as a Correct answer

Richard Sustek answered on January 21, 2015 18:27

Hi all,

The solution in this case is to publish document using the workflow manager class. This requires some additional steps. The basic example of updating a document can look like this:

           // var doc = your node here

           // Create a new Version manager instance
            VersionManager manager = VersionManager.GetInstance(tree);

            // Check out the document
            manager.CheckOut(doc);

            // Change document data
            doc.SetValue("ColumnName", "Value");

            // Save the changes
            DocumentHelper.UpdateDocument(doc, tree);

            // Check in the document
            manager.CheckIn(doc, null, null);

            WorkflowManager workflowManager = WorkflowManager.GetInstance(tree);

            WorkflowInfo workflow = workflowManager.GetNodeWorkflow(doc);

            // Check if the document uses workflow
            if (workflow != null)
            {
                // Publish the document
                workflowManager.PublishDocument(doc, null);
            }

Feel free to let me know if you have any further questions.

Kind regards,

Richard Sustek

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.