Skip to main content

Posts

Showing posts from July, 2009

SharePoint 2007 Integration With Dynamics CRM - Solution - Part 2

OK, here's the Part 2 of the solution I proposed here . We will develop a custom Web part which will display number of application forms in CRM posted from SharePoint Web site in the form of Key Performance Indicator – assume there is a target for number of application forms. We will also assume for this sample that the application form in our case will be the task which we create in CRM when new application is submitted from the SharePoint Web site. Solution 1. Create a Web part and add the Web Reference to point to the CRM Server Web Service. For CRM 3.0 it will be http://your_server:5555/mscrmservices/2006/crmservice.asmx, for CRM 4.0 it will be http://your_server:5555/mscrmservices/2007/crmservice.asmx 2. Add the following properties to the Web part class: private string _sCrmWebUrl = ...; [Personalizable(PersonalizationScope.Shared), WebBrowsable(true), WebDisplayName("CRM Web Server URL"), Category("Custom Properties")] public string CrmWebUrl { get

Query list with CAML - DateTime column

Scenario We have a SharePoint list with the column DateOfBirth which is DateTime column. We need to filter or query this list programmatically to get items where date of birth is in the certain range Solution SPList list = ... // initialize your list SPQuery query = new SPQuery(); DateTime dtDateFrom = ..., dtDateTo = ...; // our DateTime values query.Query = string.Format("<Where><And><Leq><FieldRef Name='DateOfBirth' /><Value Type='DateTime'>{0}</Value></Leq><Geq><FieldRef Name='DateOfBirth' /><Value Type='DateTime'>{1}</Value></Geq></And></Where>", SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtDateTo), SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtDateFrom)); SPListItemCollection items; items = list.GetItems(query); The above query will use only date value without time. If you would like to take time into account as well it has to look like the fo

Query list with CAML - Person or group column

Scenario We have a SharePoint list with the column Manager which is Person or group column. We need to filter or query this list programmatically to get items where certain user is the manager Solution SPList list = ... // initialize your list SPQuery query = new SPQuery(); SPUser user = ... // initialize SPUser object string sUserName = user.Name; // you just need to know user display name in SharePoint query.Query = string.Format("<Where><Contains><FieldRef Name='Manager' /><Value Type='User'>{0}</Value></Contains></Where>", sUserName); SPListItemCollection items; items = list.GetItems(query);

SharePoint 2007 Integration With Dynamics CRM - Solution - Part 1

The Scenario An organization has relationships with third-parties. Accounts, customers, members, suppliers etc. The organization has a SharePoint Web site and Dynamics CRM where the information about third-parties is processed. As the current business process dictates, large number of external clients - agents in this sample - needs to contact organization via email, fax, regular mail or in person in order to submit important business information - applications in this scenario. We will create a public SharePoint Web site where agents can submit applications and then those applications will be copied automatically to Dynamics CRM and when their processing in CRM is finished some feedback will be published back to the SharePoint Web site and agents will be able to see the status of the application in CRM online on the SharePoint Web site. We defined the solution design as below: In order to get the solution we defined the following tasks: 1. Develop a custom SharePoint Workflow which w

SharePoint 2007 Integration With Dynamics CRM - Preamble

SharePoint is a mighty platform and it has a lot of features. One of the main advantages of SharePoint is that it can be a central place of information presence in the organization. Central means other line of business applications can be integrated with SharePoint in order to expose essential business data or to consume SharePoint capabilities as an information management tool. As an example of the integration between SharePoint and business application I'm going to publish a set of articles illustrating integration of Dynamics CRM and SharePoint in order to solve business issues, increase business process efficiency and decrease costs. In this example I will demonstrate how to leverage SharePoint collaboration, workflow, extensibility and other features. Scenario An organization has relationships with third-parties. Accounts, customers, members, suppliers etc. The organization has a SharePoint Web site and Dynamics CRM where the information about third-parties is processed. As th

Key Performance Indicators - KPI List and Web Parts - review

In MOSS 2007 we have an interesting feature - Key Performance Indicators (KPI) List and Web Part. I have done some research around that matter. First I would like to show how to create KPI list with several indicators and then I would like to share some ideas for real life. KPI List When the KPI List is created we can add new indicators to that list. First will be manual indicator: This type of indicator is very simple and almost useless for real scenarios: It is for scenarios like "we just want to display some KPI". Next will be indicator based on SharePoint list: We specify the name, SharePoint list, view of the list and what we are going to count as an indicator: When we save it we can see the details view of that indicator: This option is for scenarios like "number of project tasks completed", "number of issues", "amount of expenses claimed" etc. The limitation of that indicator is that we need to create a view on the l

Dynamics CRM API - Essentials

Here is the information about how to create certain type of entities in Dynamics CRM 3.0 using API. For version 4.0 could be some changes and they will be pointed out specifically. Create a contact public Guid CreateContact() { CrmService service = new CrmService(); service.Url = ...; service.Credentials = System.Net.CredentialCache.DefaultCredentials; Guid gResult = Guid.Empty; try { contact mycontact = new contact(); mycontact.firstname = ...; mycontact.lastname = ...; ... // provide other attributes gResult = service.Create(mycontact); } catch (System.Web.Services.Protocols.SoapException soapex) { ... } catch (Exception ex) { ... } return gResult; } Create a task in regard to the contact private Guid CreateActivityForContact(Guid gContactId) { Guid gResult = Guid.Empty; CrmService service = new CrmService(); service.Url = ...; service.Credentials = Syst

Dynamics CRM API: QueryExpression In Use

During the recent SharePoint 2007 and Dynamics CRM 3.0 integration project I have come across the issue using QueryExpression class of Dynamics CRM API. Consider the following scenario: 1. We need to search for the contact in CRM using API and following criteria: contact first name and last name are equal to the values provided by search functionality or email is equal to the value provided by search functionality - email = email_value OR (first name = first_name_value AND last name = last_name_value) 2. If contact exists then we just use the identifier to do something with that contact if not exists - create the contact Initially I wrote the following code to retrieve the desired contact: string sEmail = ...; // initialize email value string sFirstName = ...; // initialize first name string sLastName = ...; // initialize last name try { QueryExpression queryContact = new QueryExpression(); queryContact.EntityName = "contact"; queryContact.ColumnSet = new AllColum

Mighty SharePoint Workflows - part 3 - workflow history and audit solutions

I came across the limitation of the workflow history in SharePoint the other day. After 60 days the history is cleaned up. Technically it's the right way of doing things in SharePoint, because workflow history is a list and if we have more than 2000 records in the list we have performance issues. There are some blog posts about that issue. The main one: Huge MOSS Workflow Issue... What is Microsoft Thinking!!!! The other linked to the issue: SPWorkflowAssociation.AutoCleanupDays I worked with several clients on custom workflows for SharePoint and we created the separate audit database where all the SharePoint workflow activity information and list/library item information is stored. For guys who have already created workflows in SharePoint or use standard SharePoint workflows - like Approval etc. - and they are not sure what to do the solution is to develop or purchase a tool to migrate their workflow history to separate database on a regular basis. I can help with that

Connect SharePoint Web Parts Programmatically

The task Send data from one Web part to another. Scenario could be like one Web part contain the list of items - say video, images or clothes catalog - and the other Web part displays detailed view of the catalog item. Solution 1. Create Web part which will send data - data producer. 1.1. When the Web part class is created we need to inherit that class from ICellProvider. The class definition will look like the following: public class DataProviderWebPart : Microsoft.SharePoint.WebPartPages.WebPart, ICellProvider { ... } 1.2. Define the following properties: public event CellProviderInitEventHandler CellProviderInit; public event CellReadyEventHandler CellReady; private int _nCellConnectedCount = 0; private string _sCellInput; private string _sCellName; private string _sCellDisplayName; 1.3. Override the following methods: EnsureInterfaces, CanRunAt, PartCommunicationConnect, PartCommunicationInit, PartCommunicationMain, CreateChildControls. public override void EnsureInterfaces()

Mighty SharePoint Workflows - part 2 - workflow statistics, workflow tasks, workflow history

The task 1. Get links to workflow statistics. 2. Get workflow tasks programmatically. 3. Get workflow history programmatically Solution 1. Links to workflow statistics: foreach (SPWorkflow wf in list_item.Workflows) { string sLink = string.Format("{0}/_layouts/WrkStat.aspx?List={1}&WorkflowInstanceID={2}", web.Url, wf.ListId, wf.InstanceId) } web.Url above is the Url property of SPWeb instance. 2. Workflow tasks: foreach (SPWorkflowTask wt in wf.Tasks) { // get any information you like about the wt object, i.e. in this scenario we will output link to the task string sLink = string.Format("{0}/Lists/{1}/DispForm.aspx?ID={2}", web.Url, SPEncode.UrlEncode(wt.ParentList.Title), wt["ID"]) ... } 3. Workflow history: Class SPWorkflow has a member HistoryList which represents history list for the workflow. Let's assume that we are using the SPWorkflow object - wf - from above. 3.1. First we have to make a query to extract history list item

Calculated Field Formulas

Have found a good Microsoft article about SharePoint calculated field formulas: Calculated Field Formulas I didn't have a lot of need to work with calculated fields, and when I needed them it was simple stuff like field1+field2, but I had no clue about how to make more complex functions. Now I have. :)

Comprehensive BDC Overview

Recently I have come across a set of article about BDC. I haven't seen anything more informative yet. Here it is: Part 1, BDC Purpose and technical architecture Part 2, Application Definition File (ADF) and its Development Part 3, Developing an ADF to Connect to Web Services Part 4, Consuming Business Data through Web Parts and SharePoint Lists Part 5, Implementing Enterprise Search with Business Data Part 6, Integrating User Profiles with Business Data Part 7, BDC Object Model

Mighty SharePoint Workflows - part 1 - workflow association, workflow instance

The task Display SharePoint lists or libraries with active workflow associations. Display item that have running or completed workflow instances and workflow status for this item. In our scenario we have a document library with associated Disposition Approval workflow started on the document: Solution 1. Get Workflow Association data for the certain list or library. SPList list = ...; // Initialize your list instance here if (list.WorkflowAssociations.Count != 0) { foreach (SPWorkflowAssociation workflowAssociation in list.WorkflowAssociations) { Guid gId = workflowAssociation.Id; string sName = workflowAssociation.Name; ... // output the values you have got // in our scenario we add them to Hashtable object hashtable.Add(gId, sName); } } 2. Get workflow instance data for the certain list item or document. We can access workflow instance data from the Workflows property of SPListItem object: foreach (SPListItem item in list.Items) {

Working with SharePoint Workflows

SharePoint 2007 out-of-the-box provides ability to associate workflows - simple pre-installed like Approval, Disposition Approval, Three-state etc. and custom workflows - with SharePoint lists or libraries. What is missing - at least in this version of SharePoint - is the ability to monitor running and/or completed workflows across the whole SharePoint Web site. As a step forward I have developed a Web part which allows people to monitor workflows across the Web site and sub-sites. I have also developed numerous custom workflows for SharePoint using Visual Studio. This post is the first in series of articles about working with SharePoint workflows programmatically. In the coming posts I will show you how to manage workflows programmatically in SharePoint. Stay tuned. :) Update: Below are the links to articles. Mighty SharePoint Workflows - part 1 - workflow association, workflow instance Mighty SharePoint Workflows - part 2 - workflow statistics, workflow tasks, workflow history Mighty

Display Subscribe to RSS feed link on SharePoint Web site

The task Expose any RSS feed link on the SharePoint Web site so visitors can subscribe to that RSS feed. Create or use existing image library to store the RSS image for the link. In this scenario we will create a Picture Library in SharePoint and upload our image there. Solution 1. Create Picture Library. 1.1. On your SharePoint Web site browse the View All Content link: 1.2. Then click Create button: 1.3. Then choose Picture Library as a type: 1.4. Provide library name and click OK: 1.5. Select Upload command to put RSS image into the Picture Library: 1.6. Browse for the image file and click OK: 1.7. Provide relevant information about the image and click OK: 2. Get the link to RSS feed. In our scenario we will use RSS feed for SharePoint calendar. 2.1. Browse to the list: 2.2. Run View RSS Feed command from the list menu: 2.3. Copy the RSS feed URL from the browser address bar: 3. Edit Web site home page in order to display RSS feed link. We will use Content Editor Web Part in this sc

Uploading file to SharePoint with metadata update

The task Programmatically upload file to SharePoint document library and update document metadata. In our scenario we will have an XML document to upload. Solution 1. Get the file contents as byte array 2. Add file to the SharePoint SPFolder object 3. Update corresponding item metadata XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(" "); using (MemoryStream ms = new MemoryStream()) { try { xDoc.Save(ms); SPFolder folder = null; SPWeb web = ... // Initialize your SPWeb object here folder = web.Folders["your_document_library_site_relative_URL"]; string sFileName = "my_new_file_name.xml"; SPFile file = folder.Files.Add(sFileName, ms.ToArray(), true); // true in Add method above is to say that we overwrite the file if it exists SPListItem item = file.Item; item[item.Fields["my_metadata_column_display_name"].InternalName] = "some_value"; ... // provid

Coding Practice for SharePoint 2007

I have started creating a Coding Practice for SharePoint. Some sort of documentation to help me and my friends developing custom applications for SharePoint. I did a quick search about that theme and have got the following links to start drilling down into the subject: Best Practices: Common Coding Issues When Using the SharePoint Object Model Best Practices: Using Disposable Windows SharePoint Services Objects Checklist for Creating SharePoint Web Parts Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 1 of 2) Development Tools and Techniques for Working with Code in Windows SharePoint Services 3.0 (Part 2 of 2) Design Guidelines for Class Library Developers C# Coding Standards SharePoint Development Best Practices – Checklist