Share via


Playing with variations in SharePoint 2013

I recently had to deliver a basic demo about new features for Variations in SharePoint 2013.

This was a very basic demo, and as I had a very limited timeframe to demonstrate these features, going to the list of Timer Jobe defintions for my demo application, and manually hitting the “Run Now” button for any single Timer Job Definition was defitely not an option.

Here below is a script that will help you starting these jobs in a correct sequence, this should help you having your hierachy created, your sites and lists, pages and listitems propagated in no time.

 

Here are the time jobs you need to run and their default Schedule:

 

Variations Create Hierarchies Job Definition Hourly
Variations Propagate List Items Job Definition Every 15 minutes
Variations Propagate Page Job Definition Every 15 minutes
Variations Propagate Sites and Lists Job Definition Every 30 minutes

This is not very convenient when it comes to demo or development as you obviously would like to have your pages almost immediately available in target variations as soon as you published a page in the source variation.

This would be the obvious execution sequence of the Timer Jobs

  • Variations Create Hierarchies Job Definition (unless you created an additional label, this one should not be executed)
  • Variations Propagate Sites and Lists Job Definition
  • Variations Propagate Page Job Definition
  • Variations Propagate List Items Job Definition

 

 Add-PSSNapin Microsoft.SharePoint.PowerShell

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

cls
function runJob($Job)
{
    write-host "Last execution time was:" $Job.LastRunTime
    [Array] $JobHistoryList=$Job.HistoryEntries
    Start-SPTimerJob $Job
    Write-Host "Running Timer Job:" -NoNewline
    Write-Host $Job.DisplayName  -NoNewline -ForegroundColor Yellow
    Write-Host " for web application: " -NoNewline
    Write-Host $targetWebApp.Url -ForegroundColor Yellow
    
    $count = $JobHistoryList.count
    $countNext = $count+1

    while ( $countNext -ne $count)
    {
    [Array] $JobHistoryList=$Job.HistoryEntries
    $count = $JobHistoryList.count
    Write-Host "=" -NoNewline
    sleep 2 
    }
    Write-Host ""
    if ($Job.status –ne "Succeeded")
    {
    Write-Host -f yellow $JobHistoryList[0].status
    Write-Host -f yellow $JobHistoryList[0].ErrorMessage
    }

    else
    {
    Write-Host -f Green $JobHistoryList[0].status 

    }
}

$webAppURL = Read-Host "Web application URL" 
$targetWebApp = Get-SPWebApplication ($webAppURL)

#VariationsCreateHierarchies job
$createHierarchies = Read-Host "Create Hierarchies ? [Y][N]"
if($createHierarchies -eq "Y")
{
    $jobName = "VariationsCreateHierarchies"
    $Job  = Get-SPTimerJob | ?{$_.Name -match $jobName} | ?{$_.Parent -eq $targetWebApp} 
    runJob($Job)
}

#VariationsSpawnSites job
$propagateSites = Read-Host "Propagate sites and lists ? [Y][N]"
if($propagateSites -eq "Y")
{
    $jobName = "VariationsSpawnSites"
    $Job  = Get-SPTimerJob | ?{$_.Name -match $jobName} | ?{$_.Parent -eq $targetWebApp} 
    runJob($Job)
}

#VariationsPropagatePage job
$propagatePage = Read-Host "Propagate pages ? [Y][N]"
if($propagatePage -eq "Y")
{
    $jobName = "VariationsPropagatePage"
    $Job  = Get-SPTimerJob | ?{$_.Name -match $jobName} | ?{$_.Parent -eq $targetWebApp} 
    runJob($Job)
}

#VariationsPropagateListItem job
$propagateListItem = Read-Host "Propagate list items ? [Y][N]"
if($propagateListItem -eq "Y")
{
    $jobName = "VariationsPropagatePage"
    $Job  = Get-SPTimerJob | ?{$_.Name -match $jobName} | ?{$_.Parent -eq $targetWebApp} 
    runJob($Job)
}

Additionally, as you will most probably want to check if the redirection logic is working properly when you created a new variations label, you will also need to change the browser local back and forth. this can be easily done by having a few .reg files at your disposal. This setting is stored in the following key:

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\International] @="" "AcceptLanguage"="fr-FR"

Just change the locale to match your variations labels, close and restart the browser and you should be redirected correctly.

Comments