9

Workflow is enabled in the system.

There is a context menu button added to the editor which makes use of Page metadata. The Event System will update the current page path in the page metadata on when the SAVE event is triggered.

But as workflow is enabled in the system, whenever I copy a page from one SG to another SG, clicking the save button explicitly will trigger the Workflow.

Until the workflow is completed I am unable to get the modified metadata in the Context menu JS code (Event System will update the modified the current page path in metadata).

Suspected reason : Unable to fetch the metadata for minor version.

Current code :

var itemId = selection.getItem(0);
var item = $models.getItem(itemId);
var contentXml = item.getStaticXmlDocument();
var currentPath = $xml.getInnerText(contentXml, "//*[local-name()='current_path']");

How should I handle the scenario in JavaScript?

2 Answers 2

6

I am not sure it works with Javascript/CME, but when dealing with CM (back-end) code, appending -v0 to a URI retrieves the latest version of an item.

Something along the lines of

var itemId = selection.getItem(0);
itemId = itemId + "-v0";

might get you on the right path. Be careful that -v0 is only accessible to the person that owns the workflow item, so you will not always be able to read it.

An alternate approach would be to call a webservice from your code that impersonates an administrator and retrieves the info from the back-end.

3
  • The solution required the major version number. What if I want to get the minor version page details and it is still under workflow? Can we get the latest page version along with minor version too through code? Feb 25, 2013 at 11:27
  • >> Can we get the latest page version along with minor version too through code? Sure, if you load both...
    – Nuno Linhares
    Feb 25, 2013 at 15:06
  • Could you please provide the code snippet how to get the minor version page details? I am trying in the below way, but error is thrown with the message item not exist. var itemId = selection.getItem(0); itemId = itemId + "-v1.2"; Feb 26, 2013 at 8:37
2

As far as I know, to get the modified contents from an item; item should be as a major version.

To know the actual version, try this

var itemId = selection.getItem(0);
var item = $models.getItem(itemId).getInfo().Version; // Example it returns as 5.0, 5.1, 5.2

As Nuno said, this version is accessible to the person who modified.

3
  • I tried getting minor version page data, but I could not succeded. I am using the following snippet for minor version, correct me if I am wrong. var itemId = selection.getItem(0); itemId = itemId + "-v1.1"; var item = $models.getItem(itemId).getInfo().Version; Throwing item not exist error.How can I solve this issue? Feb 26, 2013 at 17:37
  • @P.M.Krishna: I have already mentioned in my answer saying that there is no facility to access the minor version. Always item should be a major version for accessing. Feb 26, 2013 at 17:47
  • @P.M.Krishna: $models.getItem(itemId).getInfo().Version returns the exact version of the item which is including the minor version too. Feb 26, 2013 at 17:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.