Save Site as Template Missing

In SharePoint 2013, you cannot save a publishing site as a site template. To save the site as template try to navigate to _layouts/savetmpl.aspx . Probably you will get an error  “the save site as template is not supported on this site”.

sst

As a workaround, you can open SharePoint Designer and browse the site and look for site options and set “SaveSiteasTemplateEnabled” to true from false.

sst1

After setting this try to open the application page savetmpl.aspx from browser and you will be able to save the site as template with/without content for migration.

 

Powershell script to create custom content type in SharePoint 2013

Here is the powershell script for creating custom content type in SharePoint

Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global

$site = Get-SPSite -Identity “<<site name>>”

$web = Get-SPWeb -Identity $site.Url

########## Content Type Creation

###Custom Messages Content Type

$customctypeNameMessages = “Custom Messages Content Type”
$web.AvailableContentTypes | Select-Object Name
$customctypeParent = $web.availablecontenttypes[“Item”]
$customctype = new-object Microsoft.SharePoint.SPContentType($customctypeParent, $web.contenttypes, $customctypeNameMessages)

$customctype.Group = “Messages Content Type Group”

$web.ContentTypes.Add($customctype)

$newField = $web.Fields | where {$_.InternalName -eq “CustomMessageID”}
if($newField -ne $null)
{
$newField_fieldLink = New-OBject Microsoft.SharePoint.SPFieldLink($newField)
$customctype.FieldLinks.Add($newField_fieldLink)
}
$customctype.Update()
$web.Dispose()
$site.Dispose()
Stop-SPAssignment –Global

Power shell script to create site columns

Here is the powershell script for creating site columns for SharePoint.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Start-SPAssignment -Global

##$site
$site = Get-SPWeb -Identity “<<Site Name>>” -ErrorVariable err -ErrorAction SilentlyContinue
$Option=[Microsoft.SharePoint.SPAddFieldOptions]::AddFieldInternalNameHint

#### SITE COLUMNS
#### StatusID Number Column
$FieldSchema = ‘<Field Type=”Number” Name=”StatusID” DisplayName=”StatusID” Required=”TRUE” EnforceUniqueValues=”FALSE” Indexed=”FALSE” MaxLength=”255″ Group=”Status Columns” />’

[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “StatusID”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}
$site.Update()

#### IsActive bool Yes/No
$FieldSchema = ‘<Field Type=”Boolean” Name=”StatusIsActive” DisplayName=”StatusIsActive” Group=”Status Columns” DefaultValue=”0″ />’

[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “StatusIsActive”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}
$site.Update()

#### ApplicationLead People picker
$FieldSchema = ‘<Field Type=”User” Name=”ApplicationLead” DisplayName=”ApplicationLead” Required=”TRUE” UserSelectionMode=”PeopleOnly” Group=”Status Columns” />’

[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “ApplicationLead”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}
$site.Update()

#### RequestedDate DateTime
$FieldSchema = ‘<Field Type=”DateTime” Format=”DateOnly” Name=”RequestedDate” DisplayName=”RequestedDate” Required=”TRUE” EnforceUniqueValues=”FALSE” Indexed=”FALSE” MaxLength=”255″ Group=”Status Columns” />’

[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “RequestedDate”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}
$site.Update()

#### BusinessJustification -Rich Text
$FieldSchema = ‘<Field Type=”Note” Name=”BusinessJustification” DisplayName=”BusinessJustification” NumLines=”6″ RichText=”FALSE” Group=”Status Columns” />’

[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “BusinessJustification”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}

#### ApplicationLookup Lookup column

#Source list

$listApplication=$site.Lists.TryGetList(“Applications”)
write-host $listApplication.id
$FieldSchema = ‘<Field Type=”LookupMulti” Mult=”TRUE” List=”‘+$listApplication.id+'” ShowField=”ApplicationName” Name=”ApplicationLookup” DisplayName=”ApplicationLookup” Group=”Status Columns” />’
write-host $FieldSchema
[bool]$createColumn = $true
if($createColumn)
{
$newField = $site.Fields | where {$_.InternalName -eq “ApplicationLookup”}
if($newField -eq $null)
{
$site.Fields.AddFieldAsXml($FieldSchema)
}
}
$site.Update()

$site.Dispose()

Stop-SPAssignment -Global

Power Shell script to create custom list

Here is the script to create custom list using powershell.

Add-PSSnapin Microsoft.SharePoint.PowerShell
Start-SPAssignment -Global
# Get the site
$site = Get-SPSite -Identity “<<Site Name>>”
# Get the web
$web = Get-SPWeb -Identity $site.Url

# choose type of list
$spTemplate = $web.ListTemplates[“Custom List”]
$spListCollection = $web.Lists
#check for the list if not proceed
$spList = $spListCollection.TryGetList(“CustomMessages”)

if($spList -eq $null)
{

$spListCollection.Add(“CustomMessages”, “This list is used to store custom messages”, $spTemplate)

}
#dispose
$web.Dispose()
$site.Dispose()

Stop-SPAssignment –Global

Power Shell script to enable versioning, limit major version and check out while editing Documents in SharePoint

I came over the requirement to enable versioning for Document Libraries in all Sites/ Subsites and set major version limit to some number. Also have documents to be checked out while user tries to edit the document.

Here is the Power shell code to enable versioning, set major version limit and make documents to check out on edit.

if ((Get-PSSnapin “Microsoft.SharePoint.PowerShell” -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin “Microsoft.SharePoint.PowerShell”
}

$siteCollection = Get-SPSite “<<SiteCollection name>>”

# Iterate over all Webs in the SiteCollection
foreach($web in $siteCollection.AllWebs) {
# Look in all Lists for the title
Write-Host “Inspecting ” $web.Title
foreach ($list in $web.Lists) {

if($list.BaseType -eq “DocumentLibrary”)
{
# Enable Versioning
Write-Host “Updating ” $list.Title
$list.EnableVersioning = $true

# Enable Require documents to be checked out before they can be edited
$list.ForceCheckout = $true

# set major version limit
$list.MajorVersionLimit = 15;

$list.Update()
}
}
}

Import Active Directory Groups to SharePoint

To enable Active Directory Groups instead of individual users in SharePoint we have to change the setting under configure synchronization settings of User Profile Service Application in Central Admin to import Users and Groups and choose use SharePoint Active Directory.

ADGroupImport.png

After this run User Profile Sync and you will be able to see Active Directory Groups as well along with Users.

SharePoint Reusable Workflow(has lookup) Migration

To migrate SharePoint Designer reusable workflow, please follow below steps.

  1. Create and Develop the workflow with all the steps as required.
  2. Save the workflow as a template from source server. This will get you .wsp file saved to site assets library.wf1
  3. Go to site assets and export the file to your physical location and move wsp file to destination server.WF2.png
  4. Now go to Destination server SharePoint site where you want to move or migrate the workflow and go to Site Settings-> Solutions and upload the wsp and activate the feature/solution.WF3.png
  5. Then go site features of the site and check for the workflow feature and activate the feature.wf4
  6. That’s it if your feature is activated without any error your workflow migration is complete and success. If you find any errors while activating there may be missing lists/information for the workflow to get activated.You will be seeing migrated workflow in SharePoint Designer of Destination site.
  7. For more info also check ULS logs.
  8. Important thing is if your workflow uses references to another lists/libraries, lookups etc., make sure that all the lists are migrated before proceeding with the workflow migration.
  9. For trouble shooting with workflow errors please check this