Monday, September 19, 2016

SharePoint 2013: Multi-level Approval workflow with custom code activity using Visual Studio 2013

Learn how to use a sequential-style workflow to route a workflow to multiple level depending on the course the workflow takes.


Demonstrates how to use a sequential -style workflow to route a workflow to multiple levels depending on the approval status.  It also creates a subsite using a custom activity after approval by all level.
This basic workflow scenario supports a review and approval/reject process. The workflow starts when a list item is submitted. The workflow assigns a task to first level user group, who review the request, makes comments as necessary, and then concludes the task by either approving or rejecting the request. The workflow ends when the request is rejected. Additional tasks are assigned to the second level user group after approval from first level. On rejection, the workflow ends and on approval, a new subsite is created using the custom code activity added in the workflow.


This sample requires the following:
  • SharePoint 2013 installation that is connected to a configured Workflow Manager 1.0 farm.
  • Workflow Manager 1.0 that has the March 2013 cumulative update applied.
  • Service Bus 1.0, with the Mach 2013 cumulative update applied.
  • Visual Studio 2013 and Office Developer Tools for Visual Studio 2013
  • Start following services
    • Service Bus Gateway
    • Service Bus Message Broker
    • Workflow Service Backend

Key components of the sample

  • CPApprovalWorkflow.sln contains the entire workflow.
  • CodeActivityLibrary.csproj contains the solution to add custom workflow activity that is used by the workflow
  • The feature folder contains the feature that adds workflow to the list.

Configure and build the sample

Follow these steps to configure the sample.
  1. Make sure that you have a site collection created using the Developer Site template.
  2. Create two SharePoint user groups named Legal Dept Members and Managers
  3. Open the solution Visual Studio 2013.
  4. Change the Site URL property on the project to be the URL of the developer site.
  5. Build CodeActivityLibrary.csproj and copy the CodeActivityLibrary.dll and AllowedTypes.xml to following locations
    1. C:\Program Files\Workflow Manager\1.0\Workflow\Artifacts
    2. C:\Program Files\Workflow Manager\1.0\Workflow\WFWebRoot\bin
    3. GAC
  6. Build ApprovalWorkflowApp.sln.

Run and test the sample

  1. Open CPApprovalWorkflow.sln, set the library/list GUID in the Elements.xml file for the list to which the workflow need to be added along with Workflow History List ID and Task List ID.
  1. Build and deploy the solution to a developer site.
  2. When the solution is deployed, open the site and list to which the workflow is added to.
  3. Make entry in the list and submit.
  4. Navigate to the Task list and edit the newly created item to approve the request. (1st level)
  5. Check the Workflow log list to view the status of workflow
  6. Navigate again to the Task list and edit the item to approve (2nd level)
  7. Navigate to the Site Contents page to verify if the subsite is created successfully after approval of workflow
  8. If there is any change in the CodeActivityLibrary.csproj project, make the changes, move the CodeActivityLibrary.dll and AllowedTypes.xml to following locations, reopen the Visual Studio and add the activity again in the workflow.
    1. C:\Program Files\Workflow Manager\1.0\Workflow\Artifacts
    2. C:\Program Files\Workflow Manager\1.0\Workflow\WFWebRoot\bin
    3. GAC
  9. It’s recommended to change the Assembly version each time when there is a change in code activity library to make sure that the latest change is updated.


If the workflow fails, it is likely due to following reasons:
1. Prerequisites are not installed properly
2. GUID is not correct
3. User groups are not created
Go to workflow page to check the error message.

Screen shots

New Site Request List (where the Workflow is added to)

Workflow page of New Site Request list. Workflow started after the list form is submitted.

New task has been created and task is assigned to Legal Dept Members group

Edit the task and approve/reject the request.

Workflow History with status logged in.

New Tasks has been created and assigned to Managers group
Edit and approve/reject the request (2nd level)

Workflow History with status logged in.

Subsite created after 2 level of approvals

SharePoint 2013 Workflow error: Specified value is not supported for the |0 parameter

Environment: SharePoint 2013, Visual Studio 2013 Professional, SharePoint Visual Studio workflow

Issue: The workflow activities are completed and the workflow is running fine, however, the internal status of the workflow shows as cancelled and shows the following error in workflow page
“Specified value is not supported for the |0 parameter in SharePoint Workflow”

Workflow Error

Troubleshooting: Following is the error messages in the SharePoint log

System.NotSupportedException: Do not know how to create outbound claims for app only identity  at Microsoft.SharePoint.IdentityModel.SPIdentityContext.<GetOutboundS2SClaims>d__6.MoveNext()  at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)  at Microsoft.SharePoint.IdentityModel.OAuth2.SPOAuth2SecurityTokenManager.IssueBearerTokenString(SPServiceContext serviceContext, SPSecurityTokenServiceConnectionInformation stsInfo, OAuth2EndpointIdentity endpointIdentity, SPOAuth2SecurityTokenType tokenType, IEnumerable`1 claims) StackTrace:  at onetnative.dll: (sig=6aba1f5f-ccc4-4590-af00-b8ffe7fe99a0|2|onetnative.pdb, offset=28BE6) at onetnative.dll: (offset=152A9)
Watson bucket parameters: Microsoft SharePoint Foundation 4, ULSException14, 269cd32d "sharepoint foundation", 0f001144 "15.0.4420.0", 1f65804a "microsoft.sharepoint", 0f001144 "15.0.4420.0", 506723c5 "sat sep 29 22:07:25 2012", 00017b0d "00017b0d", 0000004c "0000004c", 760a1423 "notsupportedexception", 0018c5cc "agmxm"

Looks like the issue is because of the insufficient permission to write to event/trace log.

  1. Go to Central Admin>Monitoring>Configure diagnostic logging
  2. Select "Reset to default" from the drop down of "Least critical event to report to the event log" and "Least critical event to report to the trace log" fields.
  3. Click Ok to save

Wednesday, August 24, 2016

SharePoint 2013: Get all subsites, user groups and users from the site collection using the cross-domain library and JSOM

Summary: Learn how to use the cross-domain library in apps for SharePoint to get groups and users in a grid from an app web.

Source Code: Get Groups and Users

Last modified: 8/24/2016

This sample SharePoint hosted app demonstrates how to use the cross-domain library in SharePoint 2013 to get user groups and users list in the app web. The app deploys an grid to the app web, and displays the subsites, groups and users by using the JavaScript object model (JSOM).

Description of the sample

The code that uses the cross-domain library and a third party grid control provided by jQWidgets. The control used in this sample is a trial version. The grid displays all the subsite, user groups of each subsite and users of each group. Grid features like grouping, sorting and filtering are enabled in this app. Grouping feature of this grid helps to get the list of all users, get all groups a user is member of, and all users and groups from site collection.

Figure 1. Browser window display the grid grouped by Web and Group.

Get all user groups and users from site collection


This sample requires the following:
  • Visual Studio 2015
  • Office Developer Tools for Visual Studio 2015
  • A SharePoint 2013 development environment

For more information, see Get started developing apps for SharePoint.

Key components of the sample

The sample contains the following:
  • GetUserGroups project, which contains the AppManifest.xml file
  • GetUserGroups project
    • Default.aspx file, which contains references to SharePoint JavaScript resource files
    • App.js file, which contains code to fetch data and display results
    • jQWidget folder, which contains all the required JavaScript files and images for grid control.

Configure the sample

Follow these steps to configure the sample.
  • Update the SiteUrl property of the solution with the URL of the home page of your SharePoint website.

Run and test the sample

  1. Press F5 to build and deploy the app.
  2. Choose Trust It on the consent page to grant permissions to the app.
You should see an HTML page that displays five announcements.


For troubleshooting steps, visit the Troubleshooting the solution table in the cross-domain library documentation article.

Download source code: Get Groups and Users

Wednesday, August 10, 2016

Difference between sp.js and sp.runtime.js

The difference between sp.js and sp.runtime.js is

  • SP.js includes the SharePoint object modal references, such as web, lists, client context (which is used for representing the context of SharePoint Objects and operations), etc. It provides the types and members similar to the server object model namespace Microsoft.SharePoint to work with top-level sites, sub-sites and their lists and libraries.

  • SP.Runtime.js includes the details between client and server communication. It contains the runtime object of JavaScript and encapsulate all classes of client object model and the server interaction.

When you use JSOM, import the following libraries in the specified order.

  1. ASP.NET Ajax library
  2. sp.runtime.js
  3. sp.js 

Thursday, July 7, 2016

SharePoint 2016 step by step installation

Following are the steps to install and configure SharePoint 2016 single Server Farm


  • Windows Server 2012 R2

  • SQL Server 2012 Enterprise
  • SharePoint 2016 Prerequisites are installed.

  1. Start SharePoint 2016 RTM installation.

Start SharePoint 2016 RTM installation.

  1. Once the installation is complete, run the configuration wizard
SharePoint 2016 Run Configuration Wizard
  1. Select ‘Create a new Server’
SharePoint 2016 Configuration Wizard - connect to a server farm

  1. Provide the Database server details and click next. In this instance of single server farm, provide the current server and DB details. Since installing SharePoint 2016 in standalone machine is not supported, we need to add the current server to domain in order to configure single server farm environment. Refer to my blog post on Configuring Active Directory Domain Services for SharePoint 2016 Environment

SharePoint 2016 Configuration Wizard - Database Settings

  1. Provide Passphrase
SharePoint 2016 Configuration Wizard - Security Settings

  1. Specify server role. Select the role for the server you’re installing in the server farm. If the instance is a single server farm, then select Single Server Farm.

SharePoint 2016 Configuration Wizard - Server Role Settings

  1. Specify the central administration port number and select the authentication provide for the web application. In this instance we are selecting NTLM authentication.
SharePoint 2016 Configuration Wizard - Central Administration Settings

  1. Select Next to complete the configuration.
SharePoint 2016 Configuration Wizard

SharePoint 2016 Configuration Wizard

SharePoint 2016 Central Administration Site

Configuration Active Directory Domain Services for SharePoint 2016 Single Server Environment

Environment: Windows Server 2012 R2, SharePoint 2016 RTM Prerequisite: Install ADLDS (

Following are the steps to configure AD DS for a SharePoint 2016 Single Server Farm installation.
Start Server Manager > Select AD DS and click on more… to complete the required configuration for AD DS in the server

Configure AD DS
Click on the post deployment configuration action
Configure AD DS

Select “Add a new forest”, provide the domain name and click Next button
AD DS domain name
Provide the Directory Services Restore Mode password and click Next
Domain Controller Options
Ignore the warning message and click next

DNS Options

AD DS Domain Name
Specify the AD DS database and log location path.
AD DS Paths

Verify the details provide and click next
AD DS Review Settings

When the following error message (“Verification of prerequisites for Domain Controller promotion failed”) occurs during perquisites check, then reset the password for Administrator Account and run the prerequisite again

AD DS Prerequisites Check

AD DS Prerequisites Check
Click Install after successful prerequisite checks.

AD DS Prerequisites Check
AD DS Installation
Restart the server after successful installation.
AD DS Installation - Restart Server
Login with the credentials for new domain.
AD DS Installation - Verify Authentication

Add Users to new AD

Select Active Directory Users and Computers from Server Manager > Tools menu
AD DS - Add New Users
Add new user details
AD DS - Add New Users
Verify authentication after creating users. Now you can use this domain to configure SharePoint 2016 in a single server environment.