SharePoint 4 Developers

Additional reference guide in .NET / SharePoint Development

Programmatically Setting Conditional Formatting

Learn how to how to apply conditional formatting to views manually and programmatically by using SharePoint Designer 2010 and Visual Studio 2010 respectively.

Hi folks,

Today I want to talk about conditional formatting, which allows you to apply HTML styles to views depending on the criteria specified. This is not something new in SharePoint, in MOSS 2007 this already existed.

In this post I am going to demonstrate how to apply conditional formatting manually and programmatically, so stay tuned!

Conditional formatting in SharePoint Designer 2010

Let’s take the Grades list below as an example. Basically the idea is to implement a range of colours against the column Grade that differentiates grades. Based on the grade these colours will vary.

1_680
Figure 1 – Grades List

By using the SharePoint Designer 2010, this customisation is easy. Go to the Grades list in SharePoint Designer 2010 and open up the view called “All Items”, according to the Figure 2:

2_680
Figure 2 – All Items view

Interestingly the view can be visualised in both ways (Design and Code), which allows an easy customisation. By following the steps according to the Figure 3 the conditional formatting will be applied against the column Grade.

3_680
Figure 3 – Conditional Formatting in SharePoint 2010

Immediately after the step 3 above, you need to create a condition criteria that will do the task we need by applying a style in the Grades List.

4
Figure 4 – Condition Criteria

According to the condition criteria above, set the background colour to be Green.

Note: Different colours need to be applied against different condition criteria.

5
Figure 5 – Background colour

After configuring all the condition criteria, the conditional formatting can be visualised in different colours, according to the Figure 6:

6_680
Figure 6 – Conditional Formatting colours

The conditional formatting bar is very clear, and summarises the criteria you have specified. It allows you to configure the styles at any time. Pretty handy!

In the end you will get your the Grades List set according to the Figure 7:

7_680
Figure 7 – Conditional Formatting applied to the Grades List

Conditional formatting in Visual Studio 2010

So far you have seen how to set conditional formatting manually. Now you will see how to set this up programmatically!

First of all you need to identify the Xsl section (from Figure 6), copy all the content from this section to a xsl file, according to the code below:

Code Snippet
  1. <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal" xmlns:o="urn:schemas-microsoft-com:office:office">
  2.   <xsl:include href="/_layouts/xsl/main.xsl"/>
  3.   <xsl:include href="/_layouts/xsl/internal.xsl"/>
  4.   <xsl:param name="AllRows" select="/dsQueryResponse/Rows/Row[$EntityName = '' or (position() &gt;= $FirstRow and position() &lt;= $LastRow)]"/>
  5.   <xsl:param name="dvt_apos">&apos;</xsl:param>
  6.   <xsl:template name="FieldRef_printTableCell_EcbAllowed.Grade" match="FieldRef[@Name='Grade']" mode="printTableCellEcbAllowed" ddwrt:dvt_mode="body" ddwrt:ghost="" xmlns:ddwrt2="urn:frontpage:internal">
  7.     <xsl:param name="thisNode" select="."/>
  8.     <xsl:param name="class" />
  9.     <td>
  10.       <xsl:attribute name="style">
  11.         <xsl:if test="normalize-space($thisNode/@Grade) = 'A'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-color: #009900;</xsl:if>
  12.         <xsl:if test="normalize-space($thisNode/@Grade) = 'B'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-color: #66FF33;</xsl:if>
  13.         <xsl:if test="normalize-space($thisNode/@Grade) = 'C'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-color: #FFFF00;</xsl:if>
  14.         <xsl:if test="normalize-space($thisNode/@Grade) = 'D'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-color: #FF9900;</xsl:if>
  15.         <xsl:if test="normalize-space($thisNode/@Grade) = 'E'" ddwrt:cf_explicit="1" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">background-color: #FF0000;</xsl:if>
  16.       </xsl:attribute>
  17.  
  18.       <xsl:if test="@ClassInfo='Menu' or @ListItemMenu='TRUE'">
  19.         <xsl:attribute name="height">100%</xsl:attribute>
  20.         <xsl:attribute name="onmouseover">OnChildItem(this)</xsl:attribute>
  21.       </xsl:if>
  22.       <xsl:attribute name="class">
  23.         <xsl:call-template name="getTDClassValue">
  24.           <xsl:with-param name="class" select="$class" />
  25.           <xsl:with-param name="Type" select="@Type"/>
  26.           <xsl:with-param name="ClassInfo" select="@ClassInfo"/>
  27.         </xsl:call-template>
  28.       </xsl:attribute>
  29.       <xsl:apply-templates select="." mode="PrintFieldWithECB">
  30.         <xsl:with-param name="thisNode" select="$thisNode"/>
  31.       </xsl:apply-templates>
  32.     </td>
  33.   </xsl:template>
  34. </xsl:stylesheet>

Note: The SharePoint Designer 2010 created a subsection called xsl:attribute to store the conditional formatting you have specified (Lines 10 to 16).

In this example I am creating a feature that is going to deploy the Grades list. So check the structure of the solution for you to have an idea:

9
Figure 8 – Conditional Formatting solution

Note: The xsl files in SharePoint 2010 must be deployed under the directory Layouts\Xsl.

To deploy the Grades list I have coded the FeatureActivated method (available in the Event Receiver of the feature):

Code Snippet
  1. public override void FeatureActivated(SPFeatureReceiverProperties properties)
  2. {
  3.     SPWeb web = (SPWeb)properties.Feature.Parent;
  4.  
  5.     string grades = "Grades";
  6.  
  7.     if (web.Lists.TryGetList(grades) == null)
  8.     {
  9.         // Creating list
  10.         Guid listGuid = web.Lists.Add(grades, "", SPListTemplateType.GenericList);
  11.         SPList list = web.Lists[listGuid];
  12.         list.OnQuickLaunch = true;
  13.  
  14.         // Configuring fields
  15.         SPField title = list.Fields["Title"];
  16.         title.Title = "Name";
  17.         title.Update(true);
  18.  
  19.         list.Fields.Add("Grade", SPFieldType.Text, true);
  20.  
  21.         // Updating view
  22.         SPView mainView = list.Views[0];
  23.         mainView.ViewFields.DeleteAll();
  24.         mainView.ViewFields.Add("Attachments");
  25.         mainView.ViewFields.Add("LinkTitle");
  26.         mainView.ViewFields.Add("Grade");
  27.         mainView.XslLink = "ConditionalFormattingXsl/grades.xsl";
  28.         mainView.Update();
  29.  
  30.         // Saving changes
  31.         list.Update();
  32.     }
  33. }

Note: Pay attention to the line 27. That’s what I am talking about! Beautiful.

Once you have deployed the solution, activate it and you will get the Grades list created with the Conditional Formatting applied automatically.

8_680
Figure 9 – Feature created

Download the solution here.

To make things easier, always use SharePoint Designer to set up conditional formatting on your views. Then copy the Xsl section and paste to a xsl file. It does the trick.

I hope it helps.

References:
http://stefan-stanev-sharepoint-blog.blogspot.com/2010/08/xsltlistviewwebpart-several-xslt-tips.html
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spview.xsllink.aspx
http://office.microsoft.com/en-us/sharepoint-designer-help/apply-conditional-formatting-to-a-data-view-HA010099624.aspx

Cheers,

Marcel Medina

Click here to read the same content in Portuguese.

Article published in the .net Magazine

The article shows the reader an introduction to the Web Parts and how to develop Visual Web Parts for SharePoint 2010, showing the development with Visual Studio 2010 and how to take advantage of the features this tool offers.
 capaOnline_net80small

Hi folks,

I would like to inform that in this .net Magazine - issue 80, my exclusive article about WebPart development in SharePoint 2010 was published. Here are more details:

What is this about

The article shows the reader an introduction to the Web Parts and how to develop Visual Web Parts for SharePoint 2010, showing the development with Visual Studio 2010 and how to take advantage of the features this tool offers.

What is it for

One way to customize Web sites and portals in SharePoint is by adding Web Parts. Visual Studio 2010 now becomes a powerful ally in SharePoint 2010 development and brings new templates for development. Visual Web Parts are among these new templates that make the developer's work easier.

In which situation the subject is useful

With the release of SharePoint 2010 lots of .NET developers may begin developing in this platform easily and without trouble, unlike the previous versions that made the arise of new developers difficult. This article brings an approach to .NET developers who want to take advantage of the new features of Visual Studio 2010 to develop SharePoint 2010 solutions.

I think you'll like it! On sale now!

Link to the magazine: http://www.devmedia.com.br/post-18775-Revista--net-Magazine-Edicao-80.html

Cheers,

Marcel Medina

Click here to read the same content in Portuguese.

Business Connectivity Services – Part III

Learn how to integrate WCF services in SharePoint 2010 through Business Connectivity Services. This is a very interesting approach because it allows that different services (including the cloud) to be integrated into SharePoint 2010.

Hi folks,

After a mini holiday here there is one more part of the BCS series, whose main approach is to show how to connect to different external data sources.

Learn how to integrate WCF services in SharePoint 2010 through Business Connectivity Services. This is a very interesting approach because it allows that different services (including the cloud) to be integrated into SharePoint 2010.

In this article a WCF service will be created, so an External Content Type (ECT) can be created.

Creating ECTs via Web Service (WCF)

In order to create ECTs via Web Service it is needed the utilisation of SPD2010 and in this case, due to the fact the Web Service is going to be coded from the scratch, VS2010 is required as well.

Use this type of approach in environments that:

  • Integrates with an external data source (i.e.: other systems), either on your Intranet or Internet;
  • There is a need for creating business rules (i.e.: any validation) which can be implemented during the creation of the Web Service;
  • Uses different databases rather than SQL Server, which can be implemented in a data access layer during the creation of the Web Service;

If you have this scenario, this implementation has a higher level of difficulty by creating the Web Service. Both VS2010 and SPD2010 are utilised, the former for the Web Service development and the latter for the configuration.

Working with Visual Studio 2010

The creation of the ECT in this approach is only possible with the existence of a Web Service, that's why a solution in VS2010 is going to be created. As already mentioned in the Block 1 of the BCS Architecture (Part I), both extensions .asmx (ASP.NET Web Service Application) and .svc (WCF Service Application) can be used in the creation of ECTs, and in this demonstration I am going to use a WCF Service Application.

Start VS2010, create a Blank Solution and add 3 projects according to the Figure 1:

solution

Figure 1 - Creating the Solution

Note: Delete the files *.cs and App.config that are created by default in new projects.

The solution was split into projects that represent the data access and business logic layers. Some references between the projects need to be added, according to the Table 1:

Project Reference
ContactServices.Business ContactServices.Data
ContactServices.Host ContactServices.Business
Table 1 - References

Note: In all code examples, my goal is just to show the functionality in creating an ECT in SharePoint 2010. Don’t forget to implement the best practices and patterns such as the Application Blocks (i.e.: Logging, Exception Handling, Security, etc...). I strongly recommend the use of Enterprise Library.

Data Access Layer

In order to create the project ContactServices.Data some objects that manipulate the database need to be added, and for demonstration purposes I use the LINQ to SQL because it is simpler to implement. Add this object to the project and name it Dev.dbml, then create a new connection that uses Windows Authentication using the Server Explorer, open the database and drag the table Contact (Part II) as displayed in Figure 2:

LINQtoSQL

Figure 2 - Adding table Contact

Create a class that contains CRUD methods, so the object Contact can be handled. To do that, create a class called ContactManager and add the code below, which comments tell by themselves:

Code Snippet
  1. public class ContactManager
  2. {
  3.     /// <summary>
  4.     /// Gets all the Contacts
  5.     /// </summary>
  6.     /// <returns>Contacts Array</returns>
  7.     public Contact[] GetContacts()
  8.     {
  9.         var contacts = new List<Contact>();
  10.  
  11.         using (DevDataContext dev = new DevDataContext())
  12.         {
  13.             contacts = (from cont in dev.Contacts
  14.                         select cont).ToList();
  15.         }
  16.         return contacts.ToArray();
  17.     }
  18.  
  19.     /// <summary>
  20.     /// Gets a specific Contact
  21.     /// </summary>
  22.     /// <param name="contactId">Contact Id</param>
  23.     /// <returns>Returns the Contact</returns>
  24.     public Contact GetContactById(int contactId)
  25.     {
  26.         var contact = new Contact();
  27.  
  28.         using (DevDataContext dev = new DevDataContext())
  29.         {
  30.             contact = (from cont in dev.Contacts
  31.                         where cont.ContactID == contactId
  32.                         select cont).First();
  33.         }
  34.         return contact;
  35.     }
  36.  
  37.     /// <summary>
  38.     /// Updates a specific Contact
  39.     /// </summary>
  40.     /// <param name="contact">Contact to be updated</param>
  41.     public void UpdateContact(Contact contact)
  42.     {
  43.         var contactDB = new Contact();
  44.  
  45.         using (DevDataContext dev = new DevDataContext())
  46.         {
  47.             contactDB = (from cont in dev.Contacts
  48.                             where cont.ContactID == contact.ContactID
  49.                             select cont).First();
  50.  
  51.             // Alters the object
  52.             contactDB.Address = contact.Address;
  53.             contactDB.City = contact.City;
  54.             contactDB.CompanyName = contact.CompanyName;
  55.             contactDB.ContactName = contact.ContactName;
  56.             contactDB.ContactTitle = contact.ContactTitle;
  57.             contactDB.Country = contact.Country;
  58.             contactDB.Email = contact.Email;
  59.             contactDB.Fax = contact.Fax;
  60.             contactDB.Phone = contact.Phone;
  61.             contactDB.PostalCode = contact.PostalCode;
  62.             contactDB.Region = contact.Region;
  63.  
  64.             dev.Refresh(System.Data.Linq.RefreshMode.KeepChanges, contactDB);
  65.             dev.SubmitChanges();
  66.         }
  67.     }
  68.  
  69.     /// <summary>
  70.     /// Adds a Contact
  71.     /// </summary>
  72.     /// <param name="contact">New Contact</param>
  73.     public void AddContact(Contact contact)
  74.     {
  75.         using (DevDataContext dev = new DevDataContext())
  76.         {
  77.             dev.Contacts.InsertOnSubmit(contact);
  78.             dev.SubmitChanges();
  79.         }
  80.     }
  81.  
  82.     /// <summary>
  83.     /// Deletes a Contacts
  84.     /// </summary>
  85.     /// <param name="contactId">Contact Id</param>
  86.     public void DeleteContact(int contactId)
  87.     {
  88.         using (DevDataContext dev = new DevDataContext())
  89.         {
  90.             var contact = (from cont in dev.Contacts
  91.                             where cont.ContactID == contactId
  92.                             select cont).First();
  93.             dev.Contacts.DeleteOnSubmit(contact);
  94.             dev.SubmitChanges();
  95.         }
  96.     }
  97. }

Business Logic Layer

The project ContactServices.Business should contain Interfaces and Classes that call methods of the ContactServices.Data project. Creating Interfaces are important because of 3 main reasons in this Solution:

  • Establishes a contract for methods;
  • Sets a behaviour in classes that implement them;
  • Utilisation by WCF Service Application (project ContactServices.Host);

To perform that, create the interface IContactServices and the class called ContactServices that implements it, according to the code below:

Code Snippet
  1. [ServiceContract]
  2. public interface IContactServices
  3. {
  4.     [OperationContract]
  5.     Contact[] GetContacts();
  6.  
  7.     [OperationContract]
  8.     Contact GetContactById(int contactId);
  9.  
  10.     [OperationContract]
  11.     void UpdateContact(Contact contact);
  12.  
  13.     [OperationContract]
  14.     void AddContact(Contact contact);
  15.  
  16.     [OperationContract]
  17.     void DeleteContact(int contactId);
  18. }

 

Code Snippet
  1. public class ContactServices : IContactServices
  2. {
  3.     #region IContactServices Members
  4.  
  5.     public Contact[] GetContacts()
  6.     {
  7.         // Create your own business rules
  8.         return new ContactManager().GetContacts();
  9.     }
  10.  
  11.     public Contact GetContactById(int contactId)
  12.     {
  13.         // Create your own business rules
  14.         return new ContactManager().GetContactById(contactId);
  15.     }
  16.  
  17.     public void UpdateContact(Contact contact)
  18.     {
  19.         // Create your own business rules
  20.         new ContactManager().UpdateContact(contact);
  21.     }
  22.  
  23.     public void AddContact(Contact contact)
  24.     {
  25.         // Create your own business rules
  26.         new ContactManager().AddContact(contact);
  27.     }
  28.  
  29.     public void DeleteContact(int contactId)
  30.     {
  31.         // Create your own business rules
  32.         new ContactManager().DeleteContact(contactId);
  33.     }
  34.  
  35.     #endregion
  36. }

 

The class ContactServices contains CRUD methods that are going to be used by the BCS and tell by themselves. They work as a "thin layer" for handling data, because directly call the ContactManager methods in the project ContactServices.Data.

In this example no business rules were implemented, but you can if you need them. Just code against the methods above.

Service Host

The project ContactServices.Host was created to work as the WCF Service host, which let methods to be available for BCS consuming. Start renaming the file Service1.svc to ContactServices.svc and update the service reference at the page directive:

Code Snippet
  1. <%@ ServiceHost Language="C#" Debug="true" Service="ContactServices.Business.ContactServices" %>

 

This change is necessary because the ContactServices class needs to be mapped, which was implemented in the project ContactServices.Business. An update in the Web.config is also necessary, by editing it in the WCF Service Configuration Editor (available in the VS2010) or directly in the section system.serviceModel according to the code below:

Code Snippet
  1. <system.serviceModel>
  2.     <services>
  3.       <service behaviorConfiguration="ContactServicesBehavior" name="ContactServices.Business.ContactServices">
  4.         <endpoint binding="wsHttpBinding" bindingConfiguration="" contract="ContactServices.Business.IContactServices" />
  5.         <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="ContactServices.Business.IContactServices" />
  6.       </service>
  7.     </services>
  8.     <behaviors>
  9.       <serviceBehaviors>
  10.         <behavior name="ContactServicesBehavior">
  11.           <serviceMetadata httpGetEnabled="true" />
  12.           <serviceDebug includeExceptionDetailInFaults="true" />
  13.         </behavior>
  14.       </serviceBehaviors>
  15.     </behaviors>
  16.   </system.serviceModel>

Note: The behavior serviceDebug contains the attribute includeExceptionDetailInFaults to list in details any Web Service problem in the SharePoint Log, which is very useful during the WCF integration tests.

In the end, your solution should be similar to the Figure 3:

vstudio

Figure 3 – Final Solution

Deploy the solution in the IIS, so you can get the Url for creating the ECT, as demonstrated in the next sections.

Working with SharePoint Designer 2010

At this stage the solution was already created, and now the ECT needs to be created, by mapping the Web Service methods and parameters. The Figure 1 (Part II) displays the first step in creating the ECT, afterwards add a new connection (1) to the Web Service by choosing the External Data Source Type (2), according to the Figure 4:

conexao

Figure 4 - Creating a new connection

Set the connection parameters according to the Figure 5:

WCF

Figure 5 – WCF Connection details

Note: Some important considerations:

  • The WCF metadata can be obtained through WSDL or endpoint Mex. Both of them can be informed in the fields Service Metadata URL / Metadata Connection Mode, and are available in this solution.
  • The User’s Identity can be used to connect to the WCF service and hence to the database, that’s why the Windows Authentication is required.

After creating the WCF connection the CRUD operations need to be mapped. This is the stage in which the Web Service methods and parameters should be mapped for the creation of the ECT. For each figure below there is an operation whose parameters are displayed in tables:

addcontact

Figure 6 - AddContact Operation Properties

The operation AddContact as shown in Figure 6 has the following Input parameters according to the Tables 2 and 3:

Element .NET Type Map to Identifier Identifier Field Display Name Foreign Identifier
ContactID System.Int32 TRUE ContactID ContactID ID  
Address System.String FALSE   Address Address  
City System.String FALSE   City City  
CompanyName System.String FALSE   CompanyName Company Name  
ContactName System.String FALSE   ContactName Contact Name  
ContactTitle System.String FALSE   ContactTitle Contact Title  
Country System.String FALSE   Country Country  
Email System.String FALSE   Email E-mail  
Fax System.String FALSE   Fax Fax  
Phone System.String FALSE   Phone Phone  
PostalCode System.String FALSE   PostalCode Postal Code  
Region System.String FALSE   Region Region  
Table 2 - AddContact Operation Input Parameters

Element Default Value Filter Element Path
ContactID <<None>>   contact.ContactID
Address <<None>>   contact.Address
City <<None>>   contact.City
CompanyName <<None>>   contact.CompanyName
ContactName <<None>>   contact.ContactName
ContactTitle <<None>>   contact.ContactTitle
Country <<None>>   contact.Country
Email <<None>>   contact.Email
Fax <<None>>   contact.Fax
Phone <<None>>   contact.Phone
PostalCode <<None>>   contact.PostalCode
Region <<None>>   contact.Region
Table 3 - AddContact Operation Input Parameters (Continuation)

There are no Return parameters to be configured for the operation AddContact, so simply ignore the configuration screen and finish this mapping.

deletecontact

Figure 7 - DeleteContact Operation Properties

The operation DeleteContact as shown in Figure 7 has the following Input parameter according to the Table 4:

Element .NET Type Map to Identifier Identifier Display Name Default Value Filter Element Path
contactId System.Int32 TRUE ContactID ID <<None>>   contactId
Table 4 - DeleteContact Operation Input Parameters

getcontactbyid

Figure 8 - GetContactById Operation Properties

The operation GetContactById as shown in Figure 8 has the following Input and Return parameters according to the Tables 5, 6 and 7:

Element .NET Type Map to Identifier Identifier Display Name Default Value Filter Element Path
contactId System.Int32 TRUE ContactID ID <<None>>   contactId
Table 5 - GetContactById Operation Input Parameters

Data Source Element .NET Type Map to Identifier Identifier Field Display Name Foreign Identifier
ContactID System.Int32 TRUE ContactID ContactID ID  
Address System.String FALSE   Address Address  
City System.String FALSE   City City  
CompanyName System.String FALSE   CompanyName Company Name  
ContactName System.String FALSE   ContactName Contact Name  
ContactTitle System.String FALSE   ContactTitle Contact Title  
Country System.String FALSE   Country Country  
Email System.String FALSE   Email E-mail  
Fax System.String FALSE   Fax Fax  
Phone System.String FALSE   Phone Phone  
PostalCode System.String FALSE   PostalCode Postal Code  
Region System.String FALSE   Region Region  
Table 6 - GetContactById Operation Return Parameters

Data Source Element Element Path Required Read-Only Office Property
ContactID GetContactById.ContactID FALSE TRUE Custom Property
Address GetContactById.Address FALSE FALSE Business Address (BusinessAddress)
City GetContactById.City FALSE FALSE Business Address City (BusinessAddressCity)
CompanyName GetContactById.CompanyName FALSE FALSE Company Name (CompanyName)
ContactName GetContactById.ContactName TRUE FALSE Full Name (FullName)
ContactTitle GetContactById.ContactTitle FALSE FALSE Title (Title)
Country GetContactById.Country FALSE FALSE Business Address Country/Region (BusinessAddressCountry)
Email GetContactById.Email TRUE FALSE Email 1 Address (Email1Address)
Fax GetContactById.Fax FALSE FALSE Business Fax Number (BusinessFaxNumber)
Phone GetContactById.Phone TRUE FALSE Business Telephone Number (BusinessTelephoneNumber)
PostalCode GetContactById.PostalCode FALSE FALSE Business Address Postal Code (BusinessAddressPostalCode)
Region GetContactById.Region FALSE FALSE Business Address State (BusinessAddressState)
Table 7 - GetContactById Operation Return Parameters (Continuation)

getcontacts

Figure 9 - GetContacts Operation Properties

The operation GetContacts as shown in Figure 9 does not have Input parameters to be configured, but has the following Return parameters according to the Tables 8 and 9:

Element .NET Type Map to Identifier Identifier Field Display Name Foreign Identifier
ContactID System.Int32 TRUE ContactID ContactID ID  
Address System.String FALSE   Address Address  
City System.String FALSE   City City  
CompanyName System.String FALSE   CompanyName Company Name  
ContactName System.String FALSE   ContactName Contact Name  
ContactTitle System.String FALSE   ContactTitle Contact Title  
Country System.String FALSE   Country Country  
Email System.String FALSE   Email E-mail  
Fax System.String FALSE   Fax Fax  
Phone System.String FALSE   Phone Phone  
PostalCode System.String FALSE   PostalCode Postal Code  
Region System.String FALSE   Region Region  
Table 8 - GetContacts Operation Return Parameters

Element Element Path Required Read-Only Show in Picker Timestamp Field
ContactID GetContacts.GetContactsElement.ContactID FALSE TRUE FALSE FALSE
Address GetContacts.GetContactsElement.Address FALSE FALSE FALSE FALSE
City GetContacts.GetContactsElement.City FALSE FALSE FALSE FALSE
CompanyName GetContacts.GetContactsElement.CompanyName FALSE FALSE FALSE FALSE
ContactName GetContacts.GetContactsElement.ContactName TRUE FALSE FALSE FALSE
ContactTitle GetContacts.GetContactsElement.ContactTitle FALSE FALSE FALSE FALSE
Country GetContacts.GetContactsElement.Country FALSE FALSE FALSE FALSE
Email GetContacts.GetContactsElement.Email TRUE FALSE FALSE FALSE
Fax GetContacts.GetContactsElement.Fax FALSE FALSE FALSE FALSE
Phone GetContacts.GetContactsElement.Phone TRUE FALSE FALSE FALSE
PostalCode GetContacts.GetContactsElement.PostalCode FALSE FALSE FALSE FALSE
Region GetContacts.GetContactsElement.Region FALSE FALSE FALSE FALSE
Table 9 - GetContacts Operation Return Parameters (Continuation)

updatecontact

Figure 10 - UpdateContact Operation Properties

The operation UpdateContact as shown in Figure 10 has the following Input parameters according to the Tables 10 and 11:

Element .NET Type Map to Identifier Identifier Field Display Name Foreign Identifier
ContactID System.Int32 TRUE ContactID ContactID ID  
Address System.String FALSE   Address Address  
City System.String FALSE   City City  
CompanyName System.String FALSE   CompanyName Company Name  
ContactName System.String FALSE   ContactName Contact Name  
ContactTitle System.String FALSE   ContactTitle Contact Title  
Country System.String FALSE   Country Country  
Email System.String FALSE   Email E-mail  
Fax System.String FALSE   Fax Fax  
Phone System.String FALSE   Phone Phone  
PostalCode System.String FALSE   PostalCode Postal Code  
Region System.String FALSE   Region Region  
Table 10 - UpdateContact Operation Input Parameters

Element Default Value Filter Element Path
ContactID <<None>>   contact.ContactID
Address <<None>>   contact.Address
City <<None>>   contact.City
CompanyName <<None>>   contact.CompanyName
ContactName <<None>>   contact.ContactName
ContactTitle <<None>>   contact.ContactTitle
Country <<None>>   contact.Country
Email <<None>>   contact.Email
Fax <<None>>   contact.Fax
Phone <<None>>   contact.Phone
PostalCode <<None>>   contact.PostalCode
Region <<None>>   contact.Region
Table 11 - UpdateContact Operation Input Parameters (Continuation)

Note: Notice that in most cases just the configuration parameters (columns) nomenclature changes, but data is the same. I have decided to create configuration tables for each operation in order to facilitate the mapping with separate operations.

Once all the columns were set properly, save the ECT (1) and check the operations created (2), which can be edited at any time, according to the Figure 11:

savingECT

Figure 11 - Saving the ECT

Now it is possible to create an External List that will provide a visual interface for the external data in SharePoint 2010. In the same screen of External Content Types, choose the option External List on the context menu. Name it to “Contacts”, according to the Figure 12:

createECT

Figure 12 - Creating an External List

When the External List is created, the purpose of this article is accomplished. Now it is up to you to test the External List, which was already explained in the Part II. Reuse the same test and apply it here, since it was created for this purpose.

The fact of using a Web Service for integration in SharePoint 2010 shows us that it is possible to transmit data from and to any system that provides this interface. Unify data from different systems in SharePoint 2010! Now you know how to do it!

Reference:
http://msdn.microsoft.com/en-us/library/ee556826(v=office.14).aspx

Cheers

Marcel Medina

Click here to read the same content in Portuguese.