Search This Blog

Saturday, January 31, 2015

Deploy .wsp file using Visual Studio 2010 for SharePoint 2010 | Deploy webpart to production server using PowerShell in SharePoint

In this post we will discuss how to deploy a .wsp file using browser, PowerShell and STSADM command. This will be very much helpful when you will deploy your webpart to production server.

Also you can check out:
  1. - Deploy SharePoint 2010 solution(.wsp) package using Powershell
  2. Backup of Site collection in SharePoint 2010
  3. Enable Sign in as Different User Option in SharePoint 2013

A solution package is a distribution package that delivers your custom SharePoint Server 2010 development work to the Web servers or the application servers in your server farm. Use solutions to package and deploy custom Features, site definitions, templates, layout pages, Web Parts, cascading style sheets, and assemblies.
In SharePoint 2010 it is easy to create a .wsp file using visual studio 2010, which was previously very difficult in MOSS 2007. To deploy any solution package in any local environment in Visual Studio 2010 simply right click on the project and deploy. But to deploy the same thing in the production server we will need to deploy through .wsp file.

Steps to generate the wsp file:
Right click on the project/solution in Visual Studio 2010 then choose package. If you are building the project/solution in debug mode then you will get the .wsp file inside the Bin\Debug folder and if you are building the project in release mode then you will get the .wsp file inside the Bin\Release folder. This wsp file is needed to deploy in the production environment.

This is the best way to create the wsp file in visual studio 2010.

There are different ways you can deploy the .wsp file
-->  
Using browser:
Go to the Central Administration -> Site Actions ->Site Settings -> Galleries –> click on Solutions. After this the below page will open as shown in the figure.

Click on Upload solution and then browse to the wsp file as shown below in the figure.

Once you will click Ok then activation window will appear like below figure.

Then you can use the solution.
-->  
Using PowerShell:

Open the SharePoint 2010 Management Shell. You can get to this by going to Start > All Programs > Microsoft SharePoint 2010 Products > SharePoint 2010 Management Shell.

To add a solution using PowerShell:
Add-SPSolution {path of wsp file}
Example:
Add-SPSolution C:\MyTest.wsp

To deploy the solution using power shell
Install-SPSolution –Identity {path of wsp file}.wsp –WebApplication http://URL -GACDeployment
Example:
Install-SPSolution –Identity MyTest.wsp –WebApplication http://URL -GACDeployment

To update solution
Update-SPSolution –Identity {path of wsp file}.wsp –LiteralPath {local path of wsp file}wsp –GACDeployment

To uninstall solution
Uninstall-SPSolution –Identity {path of wsp file}.wsp –WebApplication http://
Example:
Uninstall-SPSolution –Identity MyTest.wsp –WebApplication http://URL

Remove solution
Remove-SPSolution –Identity {path of wsp file}.wsp
Example:
Remove-SPSolution –Identity MyTest.wsp

Using Stsadm:

Add the solution
stsadm -o addsolution -filename {path of wsp file}
Example:
stsadm -o addsolution -filename C:\MyTest.wsp

Deploy the solution
stsadm -o deploysolution -name {path of wsp file} -url {URL}
Example:
stsadm -o deploysolution -name MyTest.wsp -url http://URL

Retract solution:
stsadm.exe -o retractsolution -name {path of wsp file}.wsp –URL
Example:
stsadm.exe -o retractsolution -name MyTest.wsp.wsp –URL http://URL

Delete Solution
stsadm.exe -o deletesolution -name {path of wsp file}.wsp
Example:
stsadm.exe -o deletesolution -name MyTest.wsp.wsp

What is a Solution Package?


A solution is a deployable, reusable package that can contain a set of Features, site definitions, and assemblies that apply to sites, and that you can enable or disable individually. You can use the solution file to deploy the contents of a Web Part package, including assemblies, class resources, .dwp files, and other package components. A solution file has a .wsp file extension.

How to add the solution to the sharepoint farm and then deploy it to a particular web application is discussed below.

1. Adding solution package to the server

stsadm.exe -o addsolution -filename myEventCalendarList.wsp
OR
Use the complete location of the file, for example:
stsadm.exe -o addsolution -filename "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions14BINSolutionmyEventCalendarList.wsp"
Deploy solution package
Deploy solution package command

2. Deploying the Solution

Deploy the solution using the following command:
stsadm -o deploysolution -name myEventCalendarList.wsp  -url http://sp-dev/ -local  -force
Here( -url) means the web application where to deploy the solution.
OR
Goto, Central Administration > System Settings >Manage farm solutions
Now click your solution from the list (for example, myEventCalendarList.wsp).
[
65d0
caption id="attachment_381" align="alignnone" width="830" caption="Manage farm solutions"]Manage farm solutions[/caption]
a)  Now click Deploy Solution and select the web application where you want to deploy the solution (example,http://sp-dev here), Click OK when you are done.
select the web application
Click Deploy Solution
Select web application
Select web application where you want to deploy
b)  And finally you will have your solution deployed status like the following.
solution deployment status
solution deployment status
You are done with deployment.

OPTIONAL STEP (You can do it when necessary):

Now you have to enable this feature at the website to use it. To do it follow these steps:
3.  Enable the features at the website>>
Go to your Site settings> Site Collection Administration > Site collection features
And activate the feature (myEventCalendarList ,for example)  that you have installed. And add that webpart  to your site to test.

Importing SharePoint Solution Package (WSP) into Visual 
Studio 2010
In this article I’m talking about importing WSP as a result of exporting site template into visual studio 2010.
1-      Go to site setting -> Save site as template

2-Give exported template a name and description, and check Include Content checkbox in case you want to export all site contents
3- Go to site setting,  You will get a link to your “solution gallery”, which has your template.
4-Open visual studio 2010 -> Create New Project  ->Import SharePoint Solution Package
5- Select “Deploy as Farm “ option
6-Select the path of existing solution

7-    After importing this WSP, a wizard will appear with all contents of WSP and give developers to select and deselects items.
8-Visual studio Solution

Difference between SPWeb.Users, SPWeb.AllUsers, SPWeb.SiteUsers


SiteUsers,  AllUsers and  Users are properties of SPWeb Object. But looking to this properties name,  its not easy to understand their’s scope.  So below is description about this properties:-

  1. SPWeb.Users :- This represents the collection of users or user objects who have been explicitly assigned permissions in the Web site . This does not return users who have access through a group.
  2. SPWeb.AllUsers :-This gives us the collection of user objects who are either members of the site collection or who have atleast navigated to the site as authenticated members of a domain group in the site.
  3. SPWeb.SiteUsers :- This is the collection of all users that belong to the site collection
Note :
SiteUsers > AllUsers > Users 
  1. Users => explicitly provide a user permission to the site 
  2. AllUsers => Users that have accessed the site via some group membership + Users 
  3. SiteUsers => AllUsers for all subsites + site collection admins


Code:
SPWeb web = SPContext.Current.Web;
SPUserCollection c1 = web.Users;
SPUserCollection c2 = web.AllUsers;
SPUserCollection c3 = web.SiteUsers;

SharePoint Classes

SPException
The SPException object represents an exception thrown by SharePoint.
Properties: ErrorCode, NativeErrorMessage (error from unmanaged code) andNativeStackTrace (error from unmanaged code)
SPUtility
SPUtility object has a ton of useful static methodsthat you can use in your SharePoint solution>
Useful static method in Sputility: Redirect(), SendEmail(), GetGenericSetupPath(), CreateISO8601DateTimeFromSystemDateTime(), Rsolveprincipals(), HandleAccess-Denied(), GetLocalizedString(), FormatDate(), ParseDate(), AlternateServerURLFromHttpRequestUrl()
SPQuery
The SPQuery object allows you to construct queries to return specific items in a list.Use CAML.you have to come up with a Query string and the language the query is defined in is a SharePoint specific language called CAMLE.g., search our announcements lists for items with a title that contains “Test” :
<OrderBy>
<FieldRef name=”Title”>
</OrderBy>
<Where>
<Contains>
<FieldRef name=”Title”>
<Value Type=”Text”/>Test</Value>
</Contains>
</Where>

The <Contain> can be replaced with:

<EQ>, <NEQ>, <GT>, <GEQ>, <LT>, <IsNull> and <BeginsWith>

Sample code:
SPQuery query = new SPQuery();
Query.Query=”{The above mentioned CAML code}”SPListItemCollection items = list.Getitems(query);
SPSiteDataQuery
SPSiteDataQuery is like a powered up version of SPQuery. It can execute across multiple lists.
SPQuery can only execute in one particular list.
Sample code:

SPSiteDataQuery query = new SPSiteDataQuery();

query.Lists = “<Lists BaseType=’0′>”;
query.Query ==”{The above mentioned CAML code}”query.Webs=”<Websope=’SiteCollection’/>”;
query.ViewFields=”<FieldRef Name=”Title”/>;
query.RowLimit=10;
using (SPWeb web=SPContext.Current.Web) {
System.Data.DataTable table=web.getSiteData(query);
//… other things
}

SPUser
SPUser.UserToken and SPUser.Sid not availble in sanbox solution.
public override void ItemUpdating(SPItemEventProperties properties) {
SPWeb = properties.Web;

SPUser user=web.AllUsers[@”DOMAIN\ecrater”];
user.email=”xxxxxxx”;
user.Notes = “CCCCCC”;


User.Update();

Base.ItemUpdating(properties);
}


Tuesday, January 27, 2015

Sharepoint 2010 Querying Sharepoint Data

There are many ways we can query sharepoint data. Below are the objects used for querying sharepoint data.


1) SPQuery - This is used to retrieve data from a specific list.

2) SPSiteDataQuery - This is used to query data from multiple lists across different sites in a site collection.

3) CrossListQueryCache - The SharePoint CrossListQueryCache class provides a highly scalable way to run site wide queries.  It provides all the power of SPSiteDataQuery without the performance implications.  However it has some major gotchas that you should be aware of before using.

4) PortalSiteMapProvider - The PortalSiteMapProvider class allows us to access cached objects for sites, lists, and list items.

Details and Examples: 

SPQuery:

Scenario:

To get the list of items from SharePoint list whose age is greater than 10.
Assumption: Student List is created with FirstName, LastName, Age and the name of the list is Student.

Code:

SPWeb spWeb = SPContext.Current.Site.RootWeb;
SPList spList = spWeb.Lists["Students"];
SPQuery spQuery = new SPQuery();
spQuery.Query = "Write Caml query here"  //like  select * from table where Age > 10

//Execution of below line of code will return SPListItemCollection

SPListItemCollection collListItems = spList.GetItems(spQuery);
 
//Loop through each item and perform the operation

foreach (SPListItem spListItem in collListItems) {
         //Process each item
}

There will be an question arise why can't we use Linq instead of SPQuery.

If we have Linq then it needs to run under full trust proxy which is not possible in sand box solution at that time we need to use SPQuery.


SPSiteDataQuery:

Scenario: 

To get list of items from different list under multiple sites(webs) under same site collection.

Follow these steps for using the SPSiteDataQuery class
-          Create a SPSiteDataQuery instance.
-          Set properties on the SPSiteDataQuery instance to specify the lists or list types to include in the query, the individual sites to include in the query, and the CAML query itself.
-          Call the GetSiteData method on a SPWeb instance, passing in theSPSiteDataQuery instance as a parameter. The GetSiteData method returns a DataTable.

Code:

       SPSiteDataQuery dataQuery = new SPSiteDataQuery();
      //Here if we set Scope to Recursive then the query considers the current Web site and  all subsites of the current Web site. 

     //If we set Scope to SiteCollection, the query considers all Web sites that are in the same site collection as the current Web site.
    //Code snippet will be like dataQuery.Webs = "";
      dataQuery.Webs = "";
      dataQuery.Lists = "";
      dataQuery.ViewFields = "";
      dataQuery.Query =  "12345
"; 
      DataTable dtable = web.GetSiteData(dataQuery);
      //Do whatever the required operations here
 
When to use SPSiteDataQuery:
 
SPSiteDataQuery is commonly used in list aggregation scenarios, where list data from team sites or other subsites is collated and presented in a single interface. The SPSiteDataQuery will only aggregate data from SharePoint lists and will ignore data from external lists.
In terms of efficiency, the SPSiteDataQuery class provides an optimal approach to data access in the following scenarios:
-          When we need to query multiple lists within the same site collection for the same content
-          When we need to query across two or more lists that are not related by lookup columns
The SPSiteDataQuery class is optimized for querying list data across multiple sites in a site collection and across multiple lists within a single site.

CrossListQueryCache:

The SharePoint CrossListQueryCache class provides a highly scalable way to run site wide queries.
The CrossListQueryInfo object uses the CrossListQueryInfo object to get the cached results or, if there are no cached results available, it performs a cross-list query to the database and then caches the results for future use.

How to use CrossListQueryCache:
 CrossListQueryInfo query = new CrossListQueryInfo();
 query.Lists = "";
  query.Query = "" +
                          "Completed";
   query.ViewFields = "";
      query.UseCache = true;
 CrossListQueryCache cache = new CrossListQueryCache(query);
 DataTable results = cache.GetSiteData(spSite);

Where to use CrossListQueryCache:

It should be used when we need to query one or more lists and store the results in cache so subsequent calls are at near lightning speed.
There are 4 overloads for CrossListQueryCache.GetSiteData.  Two of the overloads cache the results and two do not.

CrossListQueryCache RoutineUses Cache
GetSiteData (SPSite)Yes
GetSiteData (SPWeb)No
GetSiteData (SPSite, String)Yes
GetSiteData (SPWeb, SPSiteDataQuery)No
 
So unless we are using one of the overloads that support caching and have the CrossListQueryInfo.UseCache property set to true we might as well use SPSiteDataQuery.
 
PortalSiteMapProvider: 

The PortalSiteMapProvider class allows us to access cached objects for sites, lists, and list items. It also provides methods for executing SPQuery and SPSiteDataQuery queries against cached SharePoint lists. We can use the GetCachedListItemsByQuery method to cache the query results. Executing a SPSiteDataQuery query with aPortalSiteMapProvider object is similar to using the CrossListQueryCache class.

How to use PortalSiteMapProvider:

To retrieve items from a list PortalSiteMapProvider class includes a method called GetCachedListItemsByQuery that retrieves data from a list based on a SPQuery object that is provided as a parameter to the method call.
The method then looks in its cache to see if the items already exist. If they do, the method returns the cached results, and if not, it queries the list, stores the results in cache and returns them from the method call.

Code:

SPQuery spQuery = new SPQuery();
spQuery.Query = ”” +
Completed
”;PortalSiteMapProvider ps = PortalSiteMapProvider.WebSiteMapProvider;
var pNode = ps.FindSiteMapNode(web.ServerRelativeUrl) as PortalWebSiteMapNode;

var Items = ps.GetCachedListItemsByQuery(pNode, ”Tasks”, spQuery, web);
foreach (var item in Items )
{
//Do what ever want here
}

Where to use PortalSiteMapProvider:

A primary advantage of the PortalMapSiteProvider class is its use and management of the SharePoint object cache. The object cache provides highly efficient access to objects that are not part of a list. By default, the PortalSiteMapProvider class queries and manages the object cache.

Creating Custom Workflows with SharePoint Designer 2013

Lesson Goals

  1. Learn about workflow basics.
  2. Learn how to create a List Workflow using SharePoint Designer 2013.
  3. Learn how to run a workflow.
  4. Learn how to view a workflow's history.
  5. Learn how to add Actions to a workflow.
  6. Learn how to add Conditions to a workflow.
  7. Learn how to add parameters to a workflow initiation form.
  8. Learn how to create a reusable workflow.
  9. Learn how to associate a reusable workflow with a list/library.

Workflow Basics

Workflows are a popular way to perform automated work in SharePoint. The pay versions of SharePoint Server, Standard and Enterprise, come with extra out-of-box workflows that can be associated and configured with lists and libraries using just the browser. Custom workflows can be created with software applications such as SharePoint Designer 2013 or Visual Studio 2012.
SharePoint Designer is a powerful and fairly easy-to-use tool for creating custom workflows and does not require any formal developer skills. Visual Studio, although extremely powerful in creating custom workflows, requires developer skills to use.
The walk-throughs and exercises in this course will focus on using SharePoint Designer 2013 to create custom workflows.

Custom List Workflows

SharePoint Designer 2013 is a perfect tool for creating custom workflows for lists and libraries. When you create a list workflow, it is associated with a specific list or library at creation time and has access to any metadata of the item the workflow is run against.
The following walk-through will show you how to create a very basic custom list with a couple of custom columns. Once the list is created the walk-through shows how to use SharePoint Designer 2013 to create an associated custom workflow with the list. Later walk-throughs will build upon the workflow created in this walk-through.
  1. Create a new custom list in your site named "Workflow Demo".
    1. Click the Settings menu and choose the Add an app item.
    2. Select Custom List from the template choices and type "Workflow Demo" in the Name field.
    3. Click the Create button to complete creating the list.
  2. Add a choice column named "Colors" and a text column named "Workflow Output" to Workflow Demo list.
    1. Click the Create Column link on the LIST tab toolbar.
    2. Type "Colors" in the Column name field and select Choice for the data type option.
    3. Enter "Red", "Blue", and "Green" on separate lines in the choices field within the Additional Column Settings area.
    4. Click the OK button to complete creating the column.
    5. Click the Create Column link on the LIST tab toolbar.
    6. Type "Workflow Output" in the Column name text-box field.
    7. Click the OK button to create the column.
  3. Launch SharePoint Designer 2013 and create a List Workflow associated with the Workflow Demo list.
    1. Open SharePoint Designer 2013 and then open your team site in Designer.
    2. On the Site tab toolbar, click the List Workflow drop-down button and choose the Workflow Demo list.Custom Workflows
    3. Type "Workflow Demo-WF" in the Name field of the Create List Workflow dialog and click the OK button.Custom Workflows
  4. Leave the workflow open in SharePoint Designer for the next walk-through.

Workflow Actions

Workflow Actions are the main working component in a SharePoint Designer workflow. SharePoint Designer is limited to being able only to do things that are defined in an Action. However, SharePoint comes with a wide range of Actions out-of-box. The following is a grouped list of Actions available in a default installation of SharePoint Server 2013:
  • Core Actions
    • Add a Comment
    • Add Time to Date
    • Do Calculation
    • Log to History List
    • Pause for Duration
    • Pause until Date
    • Send an Email
    • Set Time Portion of Date/Time Field
    • Set Workflow Status
    • Set Workflow Variable
    • Stop Workflow
  • Document Set Actions (not available in SharePoint Foundation)
    • Capture a version of the Document Set
    • Send Document Set to Repository
    • Set Content Approval Status for the Document Set
    • Start Document Set Approval Process
  • List Actions
    • Check In Item
    • Check Out Item
    • Copy List Item
    • Create List Item
    • Declare Record
    • Delete Item
    • Discard Check Out Item
    • Set Content Approval Status
    • Set Field in Current Item
    • Undeclare Record (not available in SharePoint Foundation)
    • Update List Item
    • Wait for Field Change in Current Item
  • Relational Actions (not available in SharePoint Foundation)
    • Lookup Manager for a User
  • Task Actions
    • Assign a Form to a Group
    • Assign a To-do Item
    • Collect Data from a User
    • Start Approval Process (not available in SharePoint Foundation)
    • Start Feedback Process (not available in SharePoint Foundation)
  • Utility Actions
    • Extract Substring from End of String
    • Extract Substring from Index of String
    • Extract Substring from Start of String
    • Extract Substring of String from Index with Length
    • Find Interval Between Dates
Some of the actions listed are not available with SharePoint Foundation 2013.
Additional Actions can be purchased, downloaded for free, or created by in-house developers and installed in SharePoint and then configured with SharePoint Designer just like out-of-the-box actions.
SharePoint Designer workflows are created by combining as many Actions as necessary to get the job done.
The following walk-through will show you how to add and configure a couple of actions to the workflow that was created in the previous walk-through.
  1. Add a Log to History List action to the Workflow Demo-WF.
    1. Click the Action drop-down button from the Workflow tab toolbar and select the Log to History List action.Workflow Actions
    2. Click the this message link inside the Log to History List action added from the previous step.Workflow Actions
    3. Type "Hello from workflow" inside the text box field.Workflow Actions
    4. Hover and click the orange bar below the Log to History List action.Workflow Actions
    5. Type "Set Field" in the text box that appears when you start typing and press the Enter key to have SharePoint Designer insert the Set Field in Current Item action.Workflow Actions
      This is just another way to add an action to a workflow. You could also use the Workflow tab's Action drop-down button like you did with the Log to History List action.
    6. Click the field link inside the Set Field in Current Item action.Workflow Actions
    7. Choose the Workflow Output field from the drop-down list.Workflow Actions
    8. Click the value link inside the Set Field in Current Item action.Workflow Actions
    9. Type "This field was set by the Workflow Demo-WF" in the value text box.
  2. Click the Publish button in the Workflows tab toolbar to publish the workflow to our SharePoint site.Workflow Actions
  3. Create a new item in the Workflow Demo list and start an instance of the Workflow Demo-WF on it.
    1. Switch back to the browser window and click the Workflow Demo link in the sites Quick Launch menu.
    2. Click the new item link inside the list.
    3. Type "Item One" for the Title field and click the Save button.
    4. Click the ellipsis button to the right of Item One and select Workflows from the drop-down.
      This is just another way to add an action to a workflow. You could also use the Workflow tab's Action drop-down button like you did with the Log to History List action.
    5. Click the Workflow Demo-WF link on the Workflows page.Workflow Actions
    6. Click the Start button on the workflows initiation page.
  4. Verify the workflow actions outcome.
    1. Verify the list now has a column titled Workflow Demo-WF and the Item One item's value for the column is Completed.
    2. Verify the Workflow Output column has the text we wrote to it through the workflow.Workflow Actions
    3. Click the Completed link in the Workflow Demo-WF column.
    4. Verify the Workflow History area has the output from our workflow action.Workflow Actions

Workflow Conditions

Workflow conditions are a way to control which Actions run or don't run within a workflow. Conditions provide workflows with If-Then and Else-If blocks to wrap Actions. SharePoint Designer provides the following conditions for use within custom workflows:
  • Common Conditions
    • If any value equals value
    • If current item field equals value
  • Other Conditions
    • Created by specific person
    • Created in a specific date span
    • Modified by a specific person
    • Modified in a specific date span
    • Person is a valid SharePoint user
    • Title field contains keywords
The following walk-through will show you how add a couple If current item field equals value conditions that will run different Log to History List actions based on valued within the Colors column of our Workflow Demo list. The conditions will be added into the Workflow Demo-WF that was created in the previous walk-through.
  1. Add If current item field equals value conditions to check for the different color values within the Colorscolumn of a Workflow Demo list item.
    1. Switch back to SharePoint Designer and the editor view of our Workflow Demo-WF workflow.
    2. Hover and click the orange bar below the last action.Workflow Conditions
    3. Click the Condition drop-down button and choose the If current item field equals value option.Workflow Conditions
    4. Click the field link in the condition and choose the Colors option from the drop-down list.Workflow Conditions
    5. Click the value link and choose the Red option from the drop-down list.Workflow Conditions
    6. Click the Else-If Branch button on the Workflow tab tool bar twice to add two more condition blocks to the workflow.Workflow Conditions
    7. Click the orange bar below the (Insert a condition) label and type "If current" and press the Enter key to have the editor fill in the rest.Workflow Conditions
    8. Click the field link inside the Else if branch and choose the Colors field from the drop-down list.Workflow Conditions
    9. Click the value link and choose the Blue color option from the drop-down list.
  2. Add a Log to History List action inside each of the condition branches.
    1. Click the (Start typing or use the Insert group in the Ribbon.) label in the first condition branch and type "Log" in the text box and press the Enter key to have the editor fill in the rest of the action.Workflow Conditions
    2. Click the this message link inside the Log to History List action and type "This items color choice was red" in the text-box field.Workflow Conditions
    3. Repeat the previous steps to add a Log to History List action inside the other two condition branches with messages reflecting "Blue" and "Green". The final condition branches should look like the following image:Workflow Conditions
  3. Click the Publish link in the Workflow tab toolbar to update the SharePoint site with the current changes.
  4. Test the condition branches in the Workflow Demo list.
    1. Switch back to the browser window and click the Workflow Demo link in the sites Quick Launch menu.
    2. Click the Workflows link from the item menu of Item One.
    3. Click the Workflow Demo-WF link under the Start a New Workflow heading.
    4. Click the Start button to start the workflow.
    5. Click the Completed link in the Workflow Demo-WF column for Item One.
    6. Verify the Workflow History has an entry with a message appropriate for the items Colors field.Workflow Conditions

Workflow Initiation Form

Initiation forms can be used with a SharePoint workflow to pass additional information into the workflow from the user who starts it. SharePoint Designer 2013 offers a wizard-driven interface for creating parameters and generating the Initiation form. The form that SharePoint Designer creates can be further customized with Microsoft InfoPath.
One drawback to using Initiation form parameters is that they work only if the workflow is manually started on an item. If a workflow is set to automatically start when an item is modified or created, then there is no opportunity for the user to interact with the Initiation form. The following shows the workflow settings and configuration tab in SharePoint designer with the Start Options and Initiation form outlined:Workflow Initiation Form
The following walk-through will show you how to add an Initiation parameter to the Workflow Demo-WF created in the previous walk-throughs in this lesson.
  1. Add Single line of text parameter named "Input Data" to the Workflow Demo-WF using SharePoint Designer.
    1. Switch back to SharePoint Designer and the editor view of our Workflow Demo-WF workflow.
    2. Click the Initiation Form Parameters button on the Workflow tab toolbar.Workflow Initiation Form
    3. Click the Add... button on the Association and Initiation Form Parameters dialog window.Workflow Initiation Form
    4. Type "Input Data" in the Field name field of the Add Field dialog window.Workflow Initiation Form
    5. Click the Next button.
    6. Click the Finish button.
    7. Click the OK button on the Association and Initiation Form Parameters dialog window.
  2. Modify the Set Field in Current Item workflow action to write the parameter information from the Initiation form into the Workflow Output field of the list item.
    1. Click the This field was set by the Workflow De... link of the Set Field in Current Item action.Workflow Initiation Form
    2. Click the fx button next to the text box to open the Lookup for Single line of text dialog window.Workflow Initiation Form
    3. Click the Data source drop-down and select the Workflow Variables and Parameters option.Workflow Initiation Form
    4. Click the Field from source drop-down and select Parameter: Input Data option.Workflow Initiation Form
    5. Click the OK button to save the settings.
  3. Click the Publish button to save the workflow changes back to the SharePoint server.
  4. Run the Workflow Demo-WF to test the Initiation form parameter.
    1. Switch back to the browser window and click the Workflow Demo link in the site's Quick Launch menu.
    2. Click the Workflows link from the item menu of Item One.
    3. Click the Workflow Demo-WF link under the Start a New Workflow heading.
    4. Type "Hello from the initiation form!" in the Input Data field of the Initiation form.Workflow Initiation Form
    5. Click the Start button to start the workflow.
    6. Verify the Workflow Output field for Item One has the text from the Initiation form.Workflow Initiation Form

Reusable Workflows

Reusable workflows allow you to create a workflow backed by a SharePoint Content Type instead of an existing list or library. Once the content type is assigned to a list or library, the workflow can be associated with that same list or library. Unlike creating a List Workflow, a reusable workflow does require extra steps of associating the workflow with the list/library. The benefit is that the workflow can be used on as many lists/libraries that support the content type without having to re-create the workflow.
The following walk-through shows how to use SharePoint Designer to create a reusable workflow for the Documentcontent type.
  1. Launch SharePoint Designer 2010 and create a Reusable Workflow associated with the Document content type.
    1. If SharePoint Designer is not already open, click the Site Actions menu and choose the Edit in SharePoint Designer option.
    2. Click the Workflows link in the Navigation menu.Reusable Workflows
    3. From the Workflows tab toolbar, click the Reusable Workflow.Reusable Workflows
    4. Type "Reusable Demo-WF" in the Name field of the Create Reusable Workflow dialog window.
    5. Select Document in the Content Type drop-down field of the Create Reusable Workflow dialog window.Reusable Workflows
    6. Click the OK button to complete creating the new reusable workflow.
  2. Add a Log to History List action to the Reusable Demo-WF workflow.
    1. Click the Action drop-down button on the Workflow tab toolbar and choose the Log to History List action.
    2. Click the this message link in the Log to History List action and click the ellipsis button to the right of the text box to open the String Builder dialog.Reusable Workflows
    3. Type "Reusable demo workflow started on: " in the text box and click the Add or Change Lookup button at the bottom of the String Builder dialog window.Reusable Workflows
    4. Select Name (for use in forms) for the Field from source field in the Lookup for String dialog window and click the OK button.Reusable Workflows
    5. Click the OK button to close the String Builder dialog.
  3. Click the Publish button in the Workflow tab toolbar to save and publish the new workflow to SharePoint.
  4. Associate the Reusable Demo-WF with the Documents library.
    1. Switch back to the browser window and click the Documents link in the sites Quick Launch menu.
    2. Click the Library Settings button on the LIBRARY tab toolbar.
    3. Click the Advanced settings link under the General Settings group.
    4. Click the Yes radio button for the Allow management of content types option.Reusable Workflows
    5. Click the OK button to save the setting.
    6. Click the Workflow Settings link under the Permissions and Management area of the Document Library Settingspage.Reusable Workflows
    7. Click the Add a workflow link.Add a workflow.
    8. Select Document in the Run on items of this type drop-down list field.Reusable Workflows
    9. Select Reusable Demo-WF in the Select a workflow template list-box field.Reusable Workflows
    10. Type "Shared Docs Reusable WF" in the Name field.
    11. Check the box labeled Creating a new item will start this workflow in the Start Options group.Reusable Workflows
    12. Click the OK button to save.
  5. Run the Shared Docs Reusable WF against an item in the Documents library.
    1. Click the Documents link in the sites Quick Launch menu.
    2. Click the new document link to upload a new document to the library.
    3. Click the Browse button.
    4. Use the Choose File to Upload dialog to select the EvaluateSharePointServer2010-ITPro document from the class files you downloaded and click the Open button.
    5. Click the OK button on the Upload Document dialog.
    6. Type "Workflow Test" in the Title field and click the Save button to complete uploading the file.
    7. Click the Completed link under the Shared Docs Reusable WF column to open the workflow history page for item.
    8. Verify the Workflow History has the text entry from the Log to History List action with the file name included.Reusable Workflows

Creating Custom List Workflows

Duration: 15 to 25 minutes.
  1. Navigate to your team site.
  2. Import the Time-off-request-list-template.stp list template file and create a new list using the template. The new list will be used later in the exercise with a custom workflow.
    1. Click the Settings menu then click the Site Settings option.Exercise - Custom Workflows
    2. Click the List templates link on the Site Settings page within the Web Designer Galleries group.Exercise - Custom Workflows
    3. Click the FILES tab to open the toolbar then click the Upload Document link button.Exercise - Custom Workflows
    4. Click the Browse button in the Upload Template dialog.
    5. Navigate to the folder you downloaded the class files to and select the Time-off-request-list-template.stp file and click the Open button on the Choose File to Upload dialog window.
    6. Click the OK button on the Add a template dialog.Exercise - Custom Workflows
    7. Click the Save button on the List Template Gallery dialog to save the file into the gallery.
    8. Click the Settings menu then choose the Add an app option.Exercise - Custom Workflows
    9. Type "time-off" in the search field and click the search icon.Exercise - Custom Workflows
    10. Select the Time-Off Requests template from the list template.Exercise - Custom Workflows
    11. Type "Time-Off Requests" in the Name: field and click the Create button to complete creating the new list.New list.
    12. Click the Time-Off Requests link in the Quick Launch and verify the new list has the following columns: Name,Start DateEnd DateReasonManager, and Manager Feedback.
      The columns were defined in the list template that the list was created with. If the list does not have these columns, make sure the list was created with the template imported in the earlier steps.
      Exercise - Custom Workflows
  3. Open the site in SharePoint Designer 2013.
  4. Using SharePoint Designer, create a new List Workflow for the Time-Off Requests list.
    1. Click the List Workflow drop-down button on the Site tab toolbar within the New group and select Time-Off Requests from the list.Exercise - Custom Workflows
    2. Type "Time-Off Request WF" in the Name field of the Create List Workflow dialog window and click the OK button to finish creating it.Exercise - Custom Workflows
  5. Add a Log to History List action to the new workflow.
    1. Click the Action drop-down button in the Workflow tab toolbar and select the Log to History List option.Exercise - Custom Workflows
    2. Click the this message link within the workflow editor work area.Exercise - Custom Workflows
    3. Click the ellipsis button next to the log message text box to open the String Builder editor.Exercise - Custom Workflows
    4. Type "Time-Off request started for:" in the Name field then with you insertion point at the end of the line after the colon and click the Add or Change Lookup button.Exercise - Custom Workflows
    5. In the Lookup for String dialog box, leave the Data source field set to Current Item and select Name in the Field from source drop-down field.Exercise - Custom Workflows
    6. Click the OK button on the Lookup for String dialog to close and save your choices.
    7. Click the OK button on the String Builder dialog to close it and save the string.
  6. Add an action that will collect data from a user using a custom task.
    1. Hover your mouse pointer under the Log to History List action you created in the previous steps and click on the orange bar that appears.Exercise - Custom Workflows
    2. Type the word "collect" and the orange bar will change into a text box like the following image:Exercise - Custom Workflows
      This is just another way to add an action to a workflow. You could also use the Workflow tab's Action drop-down button like you did with the Log to History List action.
    3. Press your Enter key to have the editor add the Collect Data from a User action.Exercise - Custom Workflows
    4. Click the data link in the Collect Data from a User action to open the Custom Task Wizard dialog.Exercise - Custom Workflows
    5. Click the Next button on the first page of the Custom Task Wizard dialog.
    6. On the second page of the Custom Task Wizard dialog, change the Name field to "Time-Off Request Task" and click the Next button.Exercise - Custom Workflows
    7. On the third page of the Custom Task Wizard dialog, click the Add button to add a new field to the custom task.Exercise - Custom Workflows
    8. Type "Time-Off Response" in the Field name field and choose Choice (menu to choose from) in the Information type drop-down field and click the Next button.Exercise - Custom Workflows
    9. Type "Approved" and "Denied" on separate lines in the Choices field of the Column Settings dialog and click theFinish button.Exercise - Custom Workflows
    10. Click the Add button back on the Custom Task Wizard dialog to add a second field to the list.Exercise - Custom Workflows
    11. Type "Manager Comments" in the Field name field and choose Multiple lines of text in the Information typedrop-down field of the Add Field dialog and click the Next button.Exercise - Custom Workflows
    12. Leave the Default value field blank and click the Finish button on the Column Settings dialog.
    13. Click the Finish button on Custom Task Wizard dialog to save the custom task.
    14. Click the this user link in the Collect Data from a User action to open the Select Users dialog.Exercise - Custom Workflows
    15. Select Workflow Lookup for a User... option within the list box and click the Add button on the Select Usersdialog.Exercise - Custom Workflows
    16. Select Manager in the Field from source drop-down list field and click the OK button on the Lookup for Person or Group dialog.Exercise - Custom Workflows
    17. Click the OK button to close and save your choice on the Select Users dialog.
  7. Add an action that will retrieve the Manager Comments from the previous task action into the Manager Feedback field of the list item.
    1. Hover and click the orange bar below Collect Data from a User action.Exercise - Custom Workflows
    2. Click the Action button drop-down in the Workflow tab toolbar and choose the Set Field in Current Item action from the list.Exercise - Custom Workflows
    3. Click the field link in the Set Field in Current Item action and choose Manager Feedback from the drop-down list.Exercise - Custom Workflows
    4. Click the value link in the Set Field in Current Item action and then click the ellipsis button to open the String Builder dialog.Exercise - Custom Workflows
    5. Type "Request feedback from Manager: " in the String Builder field and then click the Add or Change Lookupbutton.Exercise - Custom Workflows
    6. Select Association: Task List from the Data source drop-down field.Exercise - Custom Workflows
    7. Select ID from the Field drop-down field.Exercise - Custom Workflows
    8. Click the fx button next to the Value field text box.Exercise - Custom Workflows
    9. Select Workflow Variables and Parameters from the Data source field drop-down list in the Lookup for Integerdialog.Exercise - Custom Workflows
    10. Select Variable: collect from the Field from source field drop-down list in the Lookup for Integer dialog.Exercise - Custom Workflows
    11. Click the OK button to save your choices and close the Lookup for Integer dialog.
    12. Select Manager Comments from the Field from source field drop-down list.Exercise - Custom Workflows
      The Manager Comments custom task field will not show in the list until you've completed the Find the List Item portion of the Lookup for String dialog. The Find the List Item portion is how the workflow retrieves the specific task that was created by previous workflow action.
    13. Click the OK button to close the Lookup for String dialog and save your settings.
    14. Click the OK button to close the String Builder dialog and save your string.
  8. Add a Set Workflow Variable action that store the Time-Off Response of the custom task action created in previous steps. The workflow variable will be used in later steps with a condition to send different emails based on the Manager's response in the custom task.
    1. Hover and click the orange bar below Set Field in Current Item action.Exercise - Custom Workflows
    2. Select Set Workflow Variable from the Action drop-down list in the Workflow tab toolbar.Exercise - Custom Workflows
    3. Click the workflow variable link in the new action and select Create a new variable from the drop-down list.Exercise - Custom Workflows
    4. Type "Response" in the Name field and select String in the Type field and click the OK button to close the Edit Variable dialog and save your settings.Exercise - Custom Workflows
    5. Click the Value link of the Set Workflow Variable action.Exercise - Custom Workflows
    6. Click the fx button next to the Value field text box.Exercise - Custom Workflows
    7. Select Association: Task List from the Data source drop-down field.Exercise - Custom Workflows
    8. Select ID from the Field drop-down field.Exercise - Custom Workflows
    9. Click the fx button next to the Value field text box.Exercise - Custom Workflows
    10. Select Workflow Variables and Parameters from the Data source field drop-down list in the Lookup for Integerdialog.Exercise - Custom Workflows
    11. Select Variable: collect from the Field from source field drop-down list in the Lookup for Integer dialog.Exercise - Custom Workflows
    12. Click the OK button to save your choices and close the Lookup for Integer dialog.
    13. Select Time-Off Response from the Field from source field drop-down list.Exercise - Custom Workflows
      The Time-Off Response custom task field will not show in the list until you've completed the Find the List Item portion of the Lookup for String dialog. The Find the List Item portion is how the workflow retrieves the specific task that was created by previous workflow action.
    14. Click the OK button to close the Lookup for String dialog and save your settings.
  9. Add an If any value equals value condition to the workflow.
    1. Hover and click the orange bar below the last action in the workflow.Exercise - Custom Workflows
    2. Select If any value equals value option from the Condition drop-down button in the Workflow tab toolbar.Exercise - Custom Workflows
    3. Click the value link in the workflow condition.Exercise - Custom Workflows
    4. Click the fx button next to the value text box.Exercise - Custom Workflows
    5. Select Workflow Variables and Parameters for the Data source field of the Define Workflow Lookup dialog.Exercise - Custom Workflows
    6. Select Variable: response for the Field from source field of the Define Workflow Lookup dialog.Exercise - Custom Workflows
    7. Click the OK button to close the Define Workflow Lookup and save your settings.
    8. Click the value link in the workflow condition and type "Approved", without the quotes, in the text box.Exercise - Custom Workflows
  10. Add a Send an Email action inside the If condition.
    1. Hover and click the orange bar directly below the label (Start typing or use the Insert group in the Ribbon).Exercise - Custom Workflows
    2. Select Send an Email from the Action menu drop-down button on the Workflow tab toolbar.Exercise - Custom Workflows
    3. Click the these users link in the Send an Email action.Exercise - Custom Workflows
    4. Click the User Lookup icon, looks like a book, next to the To field in the Define E-mail Message dialog.Exercise - Custom Workflows
    5. Click the Workflow Lookup for a User... option and click the Add button in the Select Users dialog.Exercise - Custom Workflows
    6. Select Created By in the Field from source drop-down list field of the Lookup for Person or Group dialog.Exercise - Custom Workflows
    7. Click the OK button to close the Lookup for Person or Group dialog and save your settings.
    8. Click the OK button to close the Select Users dialog and save your settings.
    9. Type "Vacation Request Approved" in the Subject field of the Define E-mail Message dialog.
    10. Type "Your vacation request has been approved" in the Body field of the Define E-mail Message dialog and click theOK button to close and save.
  11. Add an Else block to the If condition.
    1. Hover and click the orange bar below the Send an Email action.Exercise - Custom Workflows
    2. Click the Else-If Branch button on the Workflow tab toolbar to add an Else block to the If condition.Exercise - Custom Workflows
    3. Hover and click the orange bar directly below the Else label.Exercise - Custom Workflows
    4. Select Send an Email from the Action menu drop-down button on the Workflow tab toolbar.Exercise - Custom Workflows
    5. Click the these users link in the Send an Email action.Exercise - Custom Workflows
    6. Click the User Lookup icon, which looks like a book, next to the To field in the Define E-mail Message dialog.Exercise - Custom Workflows
    7. Click the Workflow Lookup for a User... option and click the Add button in the Select Users dialog.Exercise - Custom Workflows
    8. Select Created By in the Field from source drop-down list field of the Lookup for Person or Group dialog.Exercise - Custom Workflows
    9. Click the OK button to close the Lookup for Person or Group dialog and save your settings.
    10. Click the OK button to close the Select Users dialog and save your settings.
    11. Type "Vacation Request Rejected" in the Subject field of the Define E-mail Message dialog.
    12. Type "Your vacation request has been rejected" in the Body field of the Define E-mail Message dialog and click theOK button to close and save.
  12. Save the Time-Off Request WF workflow.
    1. Click the Save icon in the upper-left corner the SharePoint Designer window.Exercise - Custom Workflows
  13. Change the Time-Off Request WF to start automatically when a new item is added to the list.
    1. Click the Time-Off Request WF breadcrumb at the top of the workflow editor area.Exercise - Custom Workflows
    2. Check the Start workflow automatically when an item is created check box under Start Options.Exercise - Custom Workflows
  14. Publish the Time-Off Request WF workflow.
    1. Click the Publish button on the Workflow Settings tab toolbar.Exercise - Custom Workflows
  15. Create a new item in the Time-Off Requests list to test the custom workflow.
    1. Switch back to your browser window or open one if you don't have one already open and browse to your site.
    2. Click the Time-Off Requests link in the site's Quick Launch menu.
    3. Click the new item link in the list.Exercise - Custom Workflows
    4. Enter the following information in the Time-Off Requests- New Item dialog and replace the Name and Managerfields with your account:
      NameSP_Admin
      Start DateSelect the following week's Monday
      End DateSelect the following week's Friday
      ReasonGoing Fishing
      ManagerSP_Admin
    5. Click the Save button to save the new time-off request item.
    6. Click the Time-Off Requests link in the site's Quick Launch menu to refresh the page.
    7. Verify the column Time-Off Request WF has been added and the status for the new list item is In Progress.Exercise - Custom Workflows
      Until the task created by the workflow is completed, the workflow will remain In Progress. Once the task is completed, the workflow will continue to the next action defined in the workflow.
  16. Complete the Time-Off Request WF custom task.
    1. Click the Site Contents link in the site's Quick Launch menu.
    2. Click the Tasks link on the Site Contents page.
    3. Click the Time-Off Request Task link to open it.Exercise - Custom Workflows
    4. Select Approved in the Time-Off Response drop-down field and type "Of course, you can have all the time off you want!" in the Manager Comments field.Exercise - Custom Workflows
    5. Click the Complete Task button to complete the task and continue the workflow.
  17. Verify the Time-Off Request WF custom workflow has completed.
    1. Click the Time-Off Requests link in the site's Quick Launch menu.Exercise - Custom Workflows
    2. Verify the Manager Feedback column includes the Manager's comments and the Time-Off Request WF column status is Completed.Exercise - Custom Workflows
    3. Click the Completed link in the Time-Off Request WF column to view the workflow history.
    4. Verify the Log to History List action in your workflow added the custom message to the history log.Exercise - Custom Workflows
  18. Verify the email was sent.
    1. Open Microsoft Outlook.
    2. Open the email message from your site with the subject of Vacation Request Approval and verify the body matches what you configured in the workflow.Exercise - Custom Workflows
    3. Close the email message and close Outlook.

Creating Reusable Workflows

Duration: 15 to 25 minutes.
  1. Create a reusable workflow for the document content type using SharePoint Designer.
    1. Navigate back to SharePoint Designer or open a new instance if you closed it from the previous exercise.
    2. If the Time-Off Request WF is still open from the previous exercise, click the Workflows breadcrumb at the top of the editor tab.Exercise - Reusable WorkflowsOr if you closed it, you can click the Workflows link in the Navigation menu.Exercise - Reusable Workflows
    3. Click the Reusable Workflow link in the WORKFLOWS tab toolbar New group.Exercise - Reusable Workflows
    4. Type "Reusable Doc WF" in the Name field and choose Document in the Content Type drop-down field and click the OKbutton.Exercise - Reusable Workflows
  2. Add an Association Column to the Reusable Doc WF.
    1. Click the Association Columns button in the WORKFLOW tab toolbar in the Variables group.Exercise - Reusable Workflows
    2. Click the Add New Column... button on the Association Columns dialog.Exercise - Reusable Workflows
    3. Type "Reusable WF Feedback" in the Field name field and click the Next button on the Add Column dialog.Exercise - Reusable Workflows
    4. Leave the Default value field empty and click the Finish button of the Column Settings dialog.
    5. Click the OK button to close the Association Columns dialog and save your column setting.
  3. Add a Set Field in Current Item action to the Reusable Doc WF and configure it to write text into the Reusable WF Feedback associated column.
    1. Hover and click the orange bar within Step 1 of the Reusable Doc WF.Exercise - Reusable Workflows
    2. Click the Action drop-down button in the Workflows tab toolbar and choose the Set Field in Current Itemaction.Exercise - Reusable Workflows
    3. Click the field link in the Set Field in Current Item action and choose the Reusable WF Feedback option from the drop-down list.Exercise - Reusable Workflows
      Only fields defined in the content type and associated columns are available to use in a reusable workflow.
    4. Click the value link in the Set Field in Current Item action.Exercise - Reusable Workflows
    5. Type "This message was created by the Reusable Doc WF!" in the value text box.
  4. Publish the Reusable Doc WF.
    1. Click the Publish button in the WORKFLOW tab toolbar's Save group.Exercise - Reusable Workflows
  5. Associate and test the Reusable Doc WF workflow with the Shared Documents library of your site.
    1. Switch back to your browser window or open one if you don't have one already open and browse to your assigned student site.
    2. Click the Documents link in the site's Quick Launch menu.Exercise - Reusable Workflows
    3. Click the FILES tab to open the toolbar and click the New Document button.Exercise - Reusable Workflows
    4. Type "This is a sample document for use with a reusable workflow." in the new Word document and click the Saveicon in the upper-left corner of the Microsoft Word window.
    5. Click Shared Documents from the Other Web Locations on the Word Save As page.
    6. Type "Sample WF Doc" in the File name field and click the Save button.
    7. Close Microsoft Word.
    8. Click the LIBRARY tab to open the toolbar and click the Library Settings button.Exercise - Reusable Workflows
    9. Click the Advanced settings link under the General Settings group.
    10. Click the Yes radio button for the Allow management of content types option.Exercise - Reusable Workflows
    11. Click the OK button to save the setting.
    12. Click the Workflow Settings link under Permissions and Management.Exercise - Reusable Workflows
    13. Click the Add a workflow link.
    14. Select Document from the Run on items of this type drop-down field.Exercise - Reusable Workflows
    15. Select Reusable Doc WF from the Select a workflow template list box.Exercise - Reusable Workflows
    16. Type "Reusable Document WF Test" in the Type a unique name for this workflow field.Exercise - Reusable Workflows
    17. Leave the rest of the workflow settings at their defaults and click the OK button at the bottom of the form.
    18. Click the Documents link in the site's Quick Launch menu to navigate back the default view of the library.
    19. Click the ellipsis link next to the Sample WF Doc link then click the second ellipsis link in the balloon pop-up to open the context menu and click the Workflows link.Exercise - Reusable Workflows
    20. Click the Reusable Document WF Test link.Exercise - Reusable Workflows
    21. Click the Start button to start the workflow.
    22. Verify the Reusable Document WF Test column has the status of Completed.Exercise - Reusable Workflows
    23. Click the ellipsis link next to the Sample WF Doc link and then click the second ellipsis link in the balloon pop-up to open the context menu and click the Edit Properties link.Exercise - Reusable Workflows
    24. Verify the Reusable WF Feedback field exists and has the text "This message created by the Reusable Doc WF!" in it.Exercise - Reusable Workflows