Category Archives: API Workflow and page state

Trigger workflow actions

After you know how to get pages from a specific workflow state you get here the information what you can do with them.

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

Page currentPg = project.getPageById(“34009”);
currentPg.submitToWorkflow();
currentPg.reject(“note name”, “reject comment”);
currentPg.release();

The first method submitToWorkflow()  can be used from an author’s perspective to confirm his changes in Tasks. It will throw a WrongStateException, if the page is not in draft state.

The last both methods are useful from a checkers perspective to return an incorrect page to the author for rework or release the changes. These methods checks for the page state too and will throw a WrongStateException too.

Before triggering one of these methods you should check the page state if you want to prevent throwing this exception.

Because I often had the need to clear the authors list of draft pages completely, because they did not want it anymore, I implemented the method resetDraftState() at Page which works as follows:

  • if the page was created (isInStateSavedAsDraftNew() == true, it will be deleted with delete()
  • if the page was upated (isInStateSavedAsDraftChanged() == true, the change will be skipped with undoChanges()

All you have to do is to call resetDraftState() on all pages you want get out of your Tasks list of draft pages. You can find more details on the determine page state article.

Get pages residing in a workflow state

Some time ago we used in one of our projects a workflow setup with an addional release check for created pages. The amount of pages currently at any state was quite high, so I added some functions to access pages currently in workflow.

RedDot CMS offer a two ways approach accessing pages in workflow:

  1. global – in SmartTree on Project node and
  2. per user – in Tasks

Accessing pages from a global point of view jRQL offers the following methods on project.

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

project.getAllPagesSavedAsDraft();
project.getAllPagesWaitingForCorrection();
project.getAllPagesWaitingForRelease();

These getAll methods all returns a PageArrayList for iterating.

If you want to offer a plugin for the author which pages he has in workflow use the author’s login information to create the CmsClient and Project and use one of the following methods:

User connectedUser = client.getConnectedUser();
connectedUser.getPagesSavedAsDraft(project);
connectedUser.getPagesWaitingForCorrection(project);
connectedUser.getPagesWaitingForRelease(project);
connectedUser.getMyPagesInWorkflow(project);

All these methods return a PageArrayList also.  Use one of these methods now to find out all pages the author currently has in the respective workflow state.

If you look at the workflow as a member of the user group able to release pages create a CmsClient and Project with your login information and use getPagesWaitingForRelease() to process them.

Determine the page state within workflow

Before you need to update a page from a program I usually check the page state. Means, is the page in draft I cannot change anything on it. Therefore the following check methods are available:

String logonGuid="0904ABF0E43443D2881FE7481339650E";
String sessionKey="490EC675042F4C5A8A6DF1ED63ADD7A6";
String projectGuid="268F46EF5EB74A75824856D3DA1C6597";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

Page currentPg = project.getPageById(“34009”);
currentPg.isInStateSavedAsDraft();
currentPg.isInStateSavedAsDraftNew();
currentPg.isInStateSavedAsDraftChanged();

currentPg.isInStateWaitingForCorrection();
currentPg.isInStateWaitingForRelease();
currentPg.isInStateReleased();

currentPg.isChangeable();
currentPg.getStateInfo();

The first method isInStateSavedAsDraft() is a simple combination of the both following savedAsDraft methods.

All of that methods look at the page state from a global point of view. The result of these methods did not depend on the pages the connected user has in his Tasks.

The method isChangeable() instead consider what pages the connect user has in workflow. Return isChangeable() true you are sure that the connected user can update the page. The currentPg is therefore in draft or globally released at all.

The last method getStateInfo() simply return a text describing the state in words.