Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7644661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:44:39+00:00 2026-05-31T09:44:39+00:00

I am working on a data export from Sitecore, from the master database. It

  • 0

I am working on a data export from Sitecore, from the master database. It gets data from items of a certain type and puts it into custom XML. I am able to generate the XML I need but now the client has asked that instead of returning data from the most recent version it return data from the version that would be published if the site was published at the time the export was performed.

The nature of the site is that it must be published on a regular but infrequent basis (once a year, I believe) but the data will be maintained continuously and anything approved in Sitecore needs to be added to another system, so doing the export from the web database is not an option, unfortunately. I am hoping to hook into whatever mechanism Sitecore uses to decide which version goes to the Web DB when/if publishing happens without actually publishing.

I have looked at Item.Publishing.GetValidVersion, IsValid, and IsPublishable but have been unsuccessful in putting them to use. I have read the Sitecore docs for those methods but the description just says “Gets the valid version.” and I am not sure what it means by “valid”.

Here is my latest attempt:

foreach (Sitecore.Data.ID courseId in courseIds)
{
  Sitecore.Data.Items.Item course = master.GetItem(courseId);
  string initialVersion  = course.Version.ToString();
  if (course != null & course.Parent.Name != "Narrative-Courses")
  {
    course = course.Publishing.GetValidVersion(DateTime.Now, true, true);
    string finalVersion = course.Version.ToString();
    if (initialVersion != finalVersion)
    {
      log(course.Name + ": " + initialVersion + ", " + finalVersion);
    }
    if (course != null)
    {
    //add xml for this item
...

My log is blank and my XML includes the highest number version of each item, regardless of workflow state. When an item has version 1 in an Approved state and version 2 in a Draft state, I only get version 2 in the XML.

Am I misinterpreting what those methods are for or just misusing them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:44:41+00:00Added an answer on May 31, 2026 at 9:44 am

    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.

    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;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with XML data from an application where we get XML like this:
Ok, so I have the following script that will export data from my database
I'm working on a project where we are dealing with importing/exporting data from database
We're working on creating a Windows service to import/export data from various places. Our
We have manage to export data from our mysql table into a .txt file.
I'm working on a product feature that will allow the user to export data
I am working on an ASP.NET MVC application where I need to export data
I am working on the data model for a relational database where I have
I am Working on Google Data api. I am taking credentials from user and
I'm working on a data distribution application which receives data from a source and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.