If you have purchased the enterprise SharePoint product Microsoft Office SharePoint Server (MOSS) 2007 then you will have seen that there are several workflows included , such as ‘Approval’, ‘Collect Feedback’, ‘Collect Signatures’ . However, at some point you are going to have to create and customise your own workflow. Fortunately, Microsoft has now provided you with Microsoft Office SharePoint Designer, which is a free product and makes this task simple and productive. To follow through the examples in this article you will need to download a copy of SharePoint Designer from Microsoft’s website.
You can customise SharePoint sites with SharePoint Designer. This is a tool for designing and developing custom workflows that then allows you to and attach these to your lists and libraries. This is done with a very simple wizard-like interface. Once you understand the concepts of creating workflow in this manner you will be surprised by what can be achieved without the need to turn to custom code and Visual Studio.
The easiest way of introducing workflow in SharePoint is to show you a simple example that makes small calculations and changes. This is slightly artificial because SharePoint also provides us with EventReceivers which are much better for small changes based upon an add/edit/delete within a list. The example used in this article would actually lend itself to an EventReceiver rather than a workflow, but serves to show the principles. To get things up and running quickly, I am going to add a custom workflow to the example begun in the first article in this series.
Planning a workflow
We are going to develop a simple workflow to manage the stock of our products and to alert a stock controller that we need more inventory when it runs short. In order to do this I have added a new column to the Products list called Inventory and set it to 500 for all our products.
Before we can begin designing this workflow, we must plan out exactly what it will do. The easiest way to do this is to draw out a flowchart-type diagram representing the process. Now you could go to town on this and use Microsoft Visio or some other drawing tool, but a simple hand drawn sketch is just as good, as long as you have an accurate idea of what your workflow needs to do. Below is a sketch of our workflow (please excuse my handwriting).
Once you have planned out your process then you need to design this in SharePoint Designer.
Creating a basic workflow
We need to attach our workflow to the Orders list so that the inventory is updated every time a new order is made.
To create a new custom workflow:
• Open SharePoint Designer.
• Select File > Open Site
• In the Site name: text box enter the full URL to your site.
• Click Open
• Select File > New > Workflow
At this point SharePoint Designer needs to retrieve some information from your site so this may take a few seconds.
You are now presented with the workflow designer. This is the main interface that you will use to create and modify your workflows. It is designed to work in stages.
• In the workflow designer type a name in the box labelled ‘Give a name to this workflow:’
• Select the Orders list from the drop down menu labelled ‘What SharePoint list should this workflow be attached to?’
• Within the options labelled ‘Select workflow start options for items in Orders:’ ensure that the checkbox labelled ‘Automatically start this workflow when a new item is created’ is checked, but none of the others.
• Click Next
You are now in a position to create a series of steps for this workflow. Each step consists of a number of lists of actions which can be executed depending upon a condition. Conditions can be selected from the list shown below. If none are specified then the actions listed will be executed regardless.
In your example you simply want to update the Inventory column for every new order so there is no condition to meet. However this is a powerful area of workflow and its worth exploring some of these different conditions.
• In the ‘Step Name’ box enter a name that indicates what this step will do. I have used ‘Update Inventory’
• Under Actions select ‘More Actions…’
• You should now see the workflow actions dialog. This will allow you to choose from a range of possible actions to perform within this workflow. If you select All Actions from the Select a Category drop down menu then you should see all available workflow actions.
• As per our workflow diagram we need to get the quantity field from our order into a variable. This is done using the ‘Set Workflow Variable’ action. So select this from the Choose an Action list, and click Add.
• You will notice that our action is represented by a sentence within the actions of this workflow step. This sentence contains links which enable you to configure the variables assigned to the action.
• Click on ‘workflow variable’ and select Create a new variable.
• In the Name box type ‘OrderQuantity’ and select Number from the Type drop down menu.
• Click OK
• In the actions list select the value link within our action.
• Now select the fx button in order to lookup a value.
• Leave Source set to Current Item
• Select Quantity in the Field drop down menu.
• You need to perform a calculation based on this, so click on Actions and select ‘Do Calculation’ you may need to select the More Actions option to find this action.
• There are three properties to set on this action so click the first ‘value’ and select the fx button.
• You need to look up the inventory of the purchased product from the Products list, so select Product in the Source drop down menu.
• Select Inventory in the Field drop down menu.
We have two additional options in this dialog now to allow us to identify the item in the products list that we want to get this value for. This type of operation is common within workflows in SharePoint so you should take some time to understand what is happening here.
Under ‘Find the List Item’ you need to choose a field and value which uniquely identify the product in question. Ideally this would be something like the ID column. However we do not have a method to retrieve the ID of the list item we are interested in, we only have the lookup column on our existing item and that contains the Product Name. However the product name should also be unique so we will use this.
• In the Field drop down menu under ‘Find the List Item’ select Products:ProductName
• Next to the Value box select the fx button to perform a lookup.
• Leave Source as Current Item, but in the Field drop down menu select Product
• Click OK to close the Define Workflow Lookup dialog.
• You will get a notification from SharePoint Designer. This is telling you that your lookup is not guaranteed to return a unique value (because you could enter the same Product Name twice); however in our situation this is acceptable so you can click Yes to continue.
• Click on the ‘plus’ within the action description and select minus.
• Click on the remaining ‘value’ within the action description and select the fx button.
• In the Source drop down menu on the Define Workflow Lookup dialog select Workflow Data.
• In the Field drop down menu select Variable: OrderQuantity
We now have a variable called Calc which contains the updated inventory count for our product. So the remaining part of our workflow is to update the Products list with the new inventory count.
• Under the actions drop down menu select Update List Item.
• Click on ‘this list’ in the action description.
• In the Update List Item dialog select Products from the List drop down menu.
• Click on Add to select a field on this list to update.
• Select Inventory under Set this field
• Click on the fx button to lookup the value.
• In the Source drop down menu on the Define Workflow Lookup dialog select Workflow Data.
• In the Field drop down menu select Variable: calc
• Click OK
• Click OK in the Value Assignment dialog
• You need to use exactly the same settings as you did previously to identify the list item within the Products list.
• Click on OK and click Yes on the warning dialog.
• Finally click Finish on the Workflow Designer dialog.
This workflow is now complete and SharePoint Designer will have attached this to the Orders list for you. If you now go and create an Order for a new Product you will see that the Inventory field on your associated Product list item is updated accordingly.
The purpose of this simple workflow has been to introduce you to the power within workflows and how they can quickly and easily simplify some of the more mundane tasks within your business processes. Now try creating a new workflow to ensure that the Total field for your order is calculated for you based on the Price field of the Products list. This uses the same skills you will have learned from this article and it will help to ‘cement’ this technique in your memory.
Next time I will be looking at how developers can create custom workflows within Visual Studio 2008 and harness the full power of Windows Workflow Foundation.
Introduction
Workflows are now an integral part for any project. You can build a SharePoint work flow using the available templates, SharePoint designer and Visual Studio 2005 / 2008. This tutorial will mainly concentrate on workflow creation using SharepPoint designer. We will walk through the basic 8 steps needed to create workflows using SharePoint designer.
I have published some videos on SharePoint, WCF, WPF, WWF, design patterns, UML, FPA, Enterprise blocks, etc. You can watch the videos here. You can download my 400 .NET FAQ EBook from here.
8 Steps to Create Workflow using SharePoint Designer
SharePoint designer helps us to create workflows and attach the workflows to a content type like list, document, etc. In other words, SharePoint designer creates workflows and publishes the workflow on the SharePoint server site.
To understand it better, we will build a simple workflow of completed and incomplete tasks. We will create two lists, one is the incomplete tasks and the other the completed tasks. The workflow will flow something like this:
• User will create a task and enter the status of the task.
• If the task is incomplete, nothing will happen.
• Once the task is marked as complete, the task will be copied from incomplete task list to completed task list.
• The task will be deleted from the incomplete task list.
So let’s understand the eight important steps we will need to create the above workflow using SharePoint designer.
Step 1
Create a team site using the SharePoint team site template.
Step 2
Create two task lists, one is incomplete task list and the other completed task list.
To create task list, click on site action -> Create: Add a new library list -> create a task.
Step 3
Start the SharePoint designer.
Step 4
Open the site in your SharePoint designer using click on file -> open site.
Step 5
Go to workflows by clicking on file -> new -> SharePoint content and click ok as shown in the below figure:
Step 6
This is an important step. In this step, we define two important things. The first is this workflow will be attached to which list. Currently we have attached the workflow to incomplete tasks list. Second we need to define the events on which the workflow should be activated. For the current scenario, we have considered two events; one when the item is created and the second when the item is updated.
Step 7
This is one more crucial step where we need to define on what condition the workflow will execute and what action should take place if the condition is true. So when a task status is completed, two actions will take place. First the task will be copied from the incomplete task list to the completed task list. Second the task is deleted from the incomplete task list.
Once you click finish, you can see the workflow created in the SharePoint designer. This workflow is also published to the SharePoint server,
You can see if the workflow is associated with the incomplete task list. Go to incomplete tasks -> Settings -> List settings -> Workflow settings. You can see that the workflow is attached to the incomplete task list.
Step 8
Ok, now it’s time to see the workflow in action. So go to incomplete task list and create a task with status completed.
Once you click ok, you see the task for some seconds in the incomplete tasks list and then the task is copied to the completed task list and deleted from the incomplete task list.
Previous SharePoint QuickStart FAQ
This article will show us how to use the Datalist in a webpart and embedding CSS file and classes in the webpart.
First we are creating the webpart. For that follow the below steps
1. Create a webpart solution
2. Create a child controls and add the related code in webpart cs file like below
DataList dlNews;
Label lblNewsTitle;
protected override void CreateChildControls()
{
// Create and add the controls that compose the
// user interface of the Web Part.
Controls.Clear();
dlNews = new DataList();
//CSS link calling as object
Microsoft.SharePoint.WebControls.CssLink cssLink = new Microsoft.SharePoint.WebControls.CssLink();
cssLink.DefaultUrl = "/_layouts/1033/styles/News.css";
this.Page.Header.Controls.Add(cssLink);
// Create the Datatable
DataTable dtItem = new DataTable();
// send the Data items from this datatable
//News Datalist view
fillResultsDatalist(dtItem);
}
private void fillResultsDatalist(DataTable dtItem)
{
// Create an instance of the DataGrid and set its
// DataSource property to the supplied DataSet.
dlNews = new DataList();
dlNews.DataSource = dtItem;
dlNews.CellPadding = 0;
dlNews.CellSpacing = 0;
dlNews.BorderWidth = 0;
dlNews.RepeatDirection = RepeatDirection.Vertical;
// Calling the Itemplete for data list bound columns
dlNews.ItemTemplate = new DatalistLabelColumn();
// Bind the data to the DataGrid.
dlNews.DataBind();
//Add the DataGrid to the controls.
Controls.Add(dlNews);
}
3. Add/Create the the ITemplate class
///
/// Intialize the Container controls
///
///
public void InstantiateIn(Control container)
{
Label lblNewsTitle = new Label();
lblNewsTitle.DataBinding += new EventHandler(this.BindLabelColumn);
container.Controls.Add(lblNewsTitle);
Label lblNewsText = new Label();
lblNewsText.DataBinding += new EventHandler(this.BindLabelColumn1);
container.Controls.Add(lblNewsText);
LinkButton lnkButton = new LinkButton();
lnkButton.DataBinding += new EventHandler(this.BindLabelColumn2);
container.Controls.Add(lnkButton);
}
///
/// BindLabelColumn for Title of the News
///
///
///
public void BindLabelColumn(object sender, EventArgs e)
{
Label lblTitle = (Label)sender;
DataListItem container = (DataListItem)lblTitle.NamingContainer;
String strVals = Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, "Titre"));
lblTitle.Text = "
> " + strVals + "
";}
///
/// BindLabelColumn1 for news Description label
///
///
///
public void BindLabelColumn1(object sender, EventArgs e)
{
Label lblText = (Label)sender;
DataListItem container = (DataListItem)lblText.NamingContainer;
String strVals = Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, "Text"));
strVals = Regex.Replace(strVals, @"<(.\n)*?>", string.Empty);
strVals = RetComments(strVals);
lblText.Text = "
" + strVals + "
";}
///
/// BindLabelColumn2 for Link button
///
///
///
public void BindLabelColumn2(object sender, EventArgs e)
{
LinkButton lnkButton = (LinkButton)sender;
DataListItem container = (DataListItem)lnkButton.NamingContainer;
String strVals = Convert.ToString(DataBinder.Eval(((DataListItem)container).DataItem, "Link"));
lnkButton.Text = @"
"
+ "> Plus d'info"
+ "
";+ "> Plus d'info"
+ "
lnkButton.PostBackUrl = strVals;
}
///
/// Substring the text upto 60 characters
///
///
///
public string RetComments(string strCompanyName)
{
string sComments = string.Empty;
if (strCompanyName.Length > 50)
{
sComments = strCompanyName.Substring(0, 50).Trim() + "...";
}
else if (strCompanyName.Length == 0)
{
sComments = "--";
}
else
{
sComments = strCompanyName;
}
return sComments;
}
4. Create the CSS page News.css.
.HomeNewsTitle,.HomeNewsSubTitle,.HomeNewsLink,.HomeSeperator,.HomeNewsTitle2,.HomeNewsLink1,.HomeNewsLink2{
font-family: Trebuchet MS;
position: relative;
float: left;
left: 0px;
width: 172px;
}
.HomeNewsTitle,.HomeNewsTitle2{
color: #0099cc;
font-size: 13px;
}
.HomeNewsTitle2{
top:4px;
}
.HomeNewsSubTitle{
color: #333333;
font-size: 12px;
line-height:15px;
}
.HomeNewsLink,.HomeNewsLink1,.HomeNewsLink2{
color: #0099cc;
font-size: 11px;
text-decoration:underline;
text-align:right;
padding-bottom:1px;
}
.HomeNewsLink1{
padding-bottom:10px;
}
.HomeNewsLink2{
bottom:5px;
}
5. Add/Place the CSS file in to below folder
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\1033\STYLES
6. you have to call the Default URL of the CSS file path like "/_layouts/1033/styles/News.css";
Now you can able to use embedded CSS classes and datalist in webpart.
I hope this will be useful for sharepoint developers.