Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up writing something to check if the current version is approved (in a workflow state marked final) and, if not, go through the older versions to find the latest one that is approved. I have not tested this rigorously but it does seem to be working correctly. It would have been clearer if I had iterated through in reverse order and returned the first one that was approved but I think this does the same thing.</p> <pre><code>public Item GetBestVersion(Item item) { Item returnItem = null; string wfIdString = item.Fields[Sitecore.FieldIDs.WorkflowState].Value; if (Sitecore.Data.ID.IsID(wfIdString)) { if (wfIdString != "") { using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master"); Sitecore.Data.ID workflowStateId = Sitecore.Data.ID.Parse(wfIdString); Sitecore.Data.Items.Item wftarget = master.GetItem(workflowStateId); if (wftarget != null) { Sitecore.Data.ID finalId = Sitecore.Data.ID.Parse("{FB8ABC73-7ACF-45A0-898C-D3CCB889C3EE}"); if (wftarget.Fields[finalId].Value == "1") { return item; } } } } } foreach (Sitecore.Data.Items.Item oldVersion in item.Versions.GetOlderVersions()) { string oldWfIdString = oldVersion.Fields[Sitecore.FieldIDs.WorkflowState].Value; if (Sitecore.Data.ID.IsID(oldWfIdString)) { if (oldWfIdString != "") { using (new Sitecore.SecurityModel.SecurityDisabler()) { Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master"); Sitecore.Data.ID workflowStateId = Sitecore.Data.ID.Parse(oldWfIdString); Sitecore.Data.Items.Item wftarget = master.GetItem(workflowStateId); if (wftarget != null) { Sitecore.Data.ID finalId = Sitecore.Data.ID.Parse("{FB8ABC73-7ACF-45A0-898C-D3CCB889C3EE}"); if (wftarget.Fields[finalId].Value == "1") { returnItem = oldVersion; } } } } } } return returnItem; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload