Tuesday, February 12, 2013

SharePoint 2013 Workflow gets canceled automatically


I was struck with the error of Workflow gets canceled automatically.
Scenario was :
A new SP 2013 installation, one server with SP, WF, etc and the other is simply SQL Server. Went through the installation steps for Workflow including the powershell bits. In designer, I am able to create a simple workflow and select 2013 as the type. When the workflow is run, is shows internal status is canceled and has the following error text below.

  • RequestorId: 55c6990b-c4a6-352c-4a5b-449fc1aecac4. Details: System.ApplicationException: HTTP 401 {"x-ms-diagnostics":["3001000;reason=\"There has been an error authenticating the request.\";category=\"invalid_client\""],"SPRequestGuid":["55c6990b-c4a6-352c-4a5b-449fc1aecac4"],"request-id":["55c6990b-c4a6-352c-4a5b-449fc1aecac4"],"X-FRAME-OPTIONS":["SAMEORIGIN"],"SPRequestDuration":["61"],"SPIisLatency":["1"],"Server":["Microsoft-IIS\/8.0"],"WWW-Authenticate":["Bearer realm=\"61e7a76b-024e-40d5-9185-2887a044d7cc\",client_id=\"00000003-0000-0ff1-ce00-000000000000\",trusted_issuers=\"00000005-0000-0000-c000-000000000000@*,00000003-0000-0ff1-ce00-000000000000@61e7a76b-024e-40d5-9185-2887a044d7cc\"","Negotiate","NTLM"],"X-Powered-By":["ASP.NET"],"MicrosoftSharePointTeamServices":[""],"X-Content-Type-Options":["nosniff"],"X-MS-InvokeApp":["1; RequireReadOnly"],"Date":["Tue, 05 Feb 2013 19:17:31 GMT"]} {"error_description":"The server was unable to process the request due to an.....

    Finally nailed it by following steps:

    1. Be sure User profile synchronization is started.

    2. The user by whom you are logged is available in User Profile list. ( In my case it was not, created new profile for the current logged in user and make sure, you are not running workflow with SharePoint system user. Please create a new user in Active directory, and using this user, create/provision workfow
          3. Final step full synchronization of User Profile Application.

and its started working!!!

Hope it saves your time

Wednesday, February 6, 2013

SharePoint 2013 Taxonomy import using .csv and Setting site navigation to use taxonomy using PowerShell

Now requirement to import taxonomy from .csv file using PowerShell as well set taxonomy as site navigation with url.

1. Create .csv file

2. Create new script and paste below code.

  [string] $siteUrl = $(throw "Error: Parameter siteUrl is required"),  
 ##Variables that should not be edited  
 $termsetName="My Navigation"  
 function CreateTerm( $parent, $name, $url )  
  Write-Host "Adding term $($parent.Name) -> $name"  
   $term = $parent.CreateTerm("$name", 1033)  
  $term.IsAvailableForTagging = $false  
  $term.SetLocalCustomProperty("_Sys_Nav_ExcludedProviders", '"CurrentNavigationTaxonomyProvider"')  
  $term.SetLocalCustomProperty("_Sys_Nav_SimpleLinkUrl", $url)  
  #$term.SetLocalCustomProperty("tIME", $url)  
  return $term  
 function GetTerm($termName, $parent)  
   $termName = [Microsoft.SharePoint.Taxonomy.TaxonomyItem]::NormalizeName($termName)  
   $term = $null  
  if( $termName -ne "" -and $parent -ne $null ){  
  if( $parent.Terms -ne $null ) {  
   $term = $parent.Terms | Where-Object {$_.Name -eq "$termName"}  
  if($term -eq $null ){  
   $term = CreateTerm -parent $parent -name "$termName" -url $_.URL  
  return $term;  
 function ImportTermSet([Microsoft.SharePoint.Taxonomy.TermSet]$set, [PSCustomObject]$terms) {   
  $terms | foreach {  
  $level1TermName = $_."Level 1 Term"  
  $level2TermName = $_."Level 2 Term"  
  $level3TermName = $_."Level 3 Term"  
   $level1Term = GetTerm -termName $level1TermName -parent $set  
  $level2Term = GetTerm -termName $level2TermName -parent $level1Term  
  $level3Term = GetTerm -termName $level3TermName -parent $level2Term   
  $ErrorActionPreference = "Continue";  
 Write-Host "Loading IIS module"  
 Import-Module WebAdministration  
 Write-Host "Loading SharePoint Commandlets"  
 Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue  
 Write-Host -ForegroundColor Green " Commandlets Loaded ... Loading Variables"  
 Write-Host "Connecting to Term Store"  
 $termsetName="My Navigation"  
 $site = Get-SPSite $siteUrl  
 $web = $site.RootWeb  
 $session = [Microsoft.SharePoint.Publishing.Navigation.TaxonomyNavigation]::CreateTaxonomySessionForEdit($web)  
 $store = $session.TermStores[0]    
 $group = $session.TermStores.Groups | Where-Object {$_.SiteCollectionAccessIds -eq $site.ID }  
 $navigationSet = $group.TermSets | where { $_.Name -eq $termsetName }  
 if( $navigationSet -ne $null -and $emptyfirst) {  
  Write-Host -ForegroundColor Yellow "Removing existing termset"  
  $navigationSet = $null  
 if( $navigationSet -eq $null) {  
  Write-Host -ForegroundColor Yellow "Creating termset"  
  $navigationSet = $group.CreateTermSet($termsetName)  
 $navigationSet.SetCustomProperty("_Sys_Nav_IsNavigationTermSet", "True")  
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_SiteId", $site.ID.ToString())  
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_WebId", $site.RootWeb.ID.ToString())   
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_OriginalUrl", $site.RootWeb.Url )  
 $date = Get-Date -Format "yyyy-MM-ddTHH:mm:ssZ"   
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_Timestamp", $date )  
 Write-Host "Importing Term Set CSV File"  
 $scriptpath = $MyInvocation.MyCommand.Path  
 $dir = Split-Path $scriptpath  
 $fileEntries = [IO.Directory]::GetFiles($dir);   
 foreach($fileName in $fileEntries)   
  if($ext -eq ".csv")  
  Write-Host -ForegroundColor Green "Processing $fileName"  
  $terms = Import-Csv -Delimiter ';' $fileName  
  ImportTermSet $navigationSet $terms  
  "All term sets have been imported"  
 Write-Host "Setting site nav to use taxonomy"  
 $settings = new-object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings($web);  
 $settings.GlobalNavigation.Source = [Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::TaxonomyProvider  
 $settings.GlobalNavigation.TermStoreId = $store.Id  
 $settings.GlobalNavigation.TermSetId = $navigationSet.Id  

Note :
1. Script file and .csv file should be in same folder.
2. This script supports import for multiple .csv files too. However it has to be in same folder.
3. Script will look for .csv in the current folder and will do import to Term store.
4.As well this script will set site navigation to use the taxonomy, It will set the navigation link with provided url to the term.

Tuesday, February 5, 2013

SharePoint 2013 TermSet with PowerShell

Create new script with following code:

$session = Get-SPTaxonomySession -Site "Your site Url"
$termStore = $session.TermStores[“Managed Metadata Application”] - change your managed metadata service name
$group = $termstore.CreateGroup(“My New Group”)
$group.Description = "My Term Group"
$termSet = $group.CreateTermSet(“My TermSet”,1033)
$termSet.Description = My TermSet
$termSet.IsAvailableForTagging = $true
$termSet.IsOpenForTermCreation = $true

To enable the term set for navigation, i.e  "Use this Term Set for Site Navigation" 
use following code to make it enabled.

$navigationSet = $group.CreateTermSet($termsetName)
 $navigationSet.SetCustomProperty("_Sys_Nav_IsNavigationTermSet", "True")
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_SiteId", $site.ID.ToString())
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_WebId", $site.RootWeb.ID.ToString())    
 $navigationSet.SetCustomProperty("_Sys_Nav_AttachedWeb_OriginalUrl", $site.RootWeb.Url )
You can check your new termset inside "My New Group" : go to  site management -> Term Store Management.