Setting Permissions for an External Content Type

In a previous post, I created an External Content Type based on the following Stored Procedures:

  • dbo.BcsSalesForecastReadList
  • dbo.BcsSalesForecastReadItem

Before you can use the External Content Type the permissions must be set.   The permissions are set using the SharePoint 2010 Central Administration Panel.  Open the Central Administration Panel and you should see the following:

image

Under the Application Management Section click on the Manage Service Application settings link.  Next Click on the Business Connectivity Data Service and you should see the External Content Type called BcsSalesForecast:

image

Hover over the BcsSalesForecast External Content Type and select “Set Permissions” from the drop down box:

image 

Type in the username (Domain\userid) and click check names to verify the user and then click Add.  Once the user or users are added you can set the permissions.  When I was adding my user id I found that I had to be connected to my domain in order to add my account.  For example, if you are using laptop at home and you are not connected to your companies domain you probably won’t be able to add the account to the External Content Type.  If you have VPN Access to you company network then you can connect to the Domain and then try adding the Account.

image

Once the permissions have been set you can now create an External List based on the External Content Type using the SharePoint Designer.  Just Navigate to the External Content Type in the SharePoint Designer and Select BcsSalesForecast and then click External List located in the Ribbon as shown below:

image

This will create an External List called Sales Forecast. Because only ReadList and ReadItem operations are defined for the External Content Type, for now, you can only view all the items in for the Forecast or view the details of one item.

image

If you have not set the permission for the External Content Type you will receive the following error when you try to access the External List:

Access denied by Business Data Connectivity.

Troy

Creating an External Content Type in SharePoint 2010

In a previous post I created a simple weekly sales forecasting table which will be used as a starting point to create an External Content Type.  Below is some sample data from the table:

image

When a External Content Type is created the data source can be a table, view, store procedures or a web services.  The External Content support various operation but you must provide functionality for the following two operations:

  • Read List
  • Read Item

These two operations must defined in order to use the External Content Type as an External List in SharePoint 2010.  For this example I am going to create two stored procedures for the operations:

  • dbo.BcsSalesForecastReadList
  • dbo.BcsSalesForecastReadItem

Before the External Content Type Operations can be created we need to create the stored procedures that will be used to read an item from the external content type and list all items in the external content type.    The Read List stored procedure for our sales forecast data is fairly simple.  The stored procedure simple needs to return all the rows and columns we want to be available in the External Content Type.  Why use a stored procedure then for this operation?   For simple lists of information a using a table or view is fine but if you want to have a high level of flexibility and control then a store procedure is probably a better choice.    A Web Service would provide even more power and platform independence but for our sales forecast application our approach will suffice.

dbo.BcsSalesForecastReadList

create procedure dbo.BcsSalesForecastReadList as set nocount on select EnglishMonthName + '-' + WeekNumber + '-' + SalesTerritoryRegion + '-' + Category ID, EnglishMonthName MonthName, WeekNumber, SalesTerritoryGroup SalesGroup, SalesTerritoryRegion SalesRegion, Category ProductCategory, LastYearAmount, ForecastAmount from dbo.WeeklySalesForecast

dbo.BcsSalesForecastReadItem

create procedure dbo.BcsSalesForecastReadItem @ID nvarchar(255) as set nocount on select fcst.ID, fcst.MonthName, fcst.WeekNumber, fcst.SalesGroup, fcst.SalesRegion, fcst.ProductCategory,  fcst.LastYearAmount, fcst.ForecastAmount from ( select EnglishMonthName + '-' + WeekNumber + '-' + SalesTerritoryRegion + '-' + Category ID, EnglishMonthName MonthName, WeekNumber, SalesTerritoryGroup SalesGroup, SalesTerritoryRegion SalesRegion, Category ProductCategory, LastYearAmount, ForecastAmount from dbo.WeeklySalesForecast) fcst where ID = @ID

For the purposes of this demo I have created a unique Business Key (ID) which concatenates (joins) the following fields:

  • EnglishMonthName
  • WeekNumber
  • SalesTerritoryRegion
  • Category

This combination uniquely identifies each row in the forecast table.   Ideally you could used an identity column or create proper indexes using the 4 columns. 

Connect to the site that was created in the last post or you can use one of your existing sites.  Open SharePoint Designer and open the following site:

image

Click on the External Content Types site object in the Navigation Pane on the right hand side.  Create a New External Content Type.  You should see the following screen:

image

Enter the following:

  • Name: BcsSalesForecast
  • Display Name: Bcs Sales Forecast

In the External Content Type Operation section click “Click here to discover external data sources and define operations” .  You should see a screen similar to this:

image

Click “Add Connection” and select the Data Source Type as SQL Server.  Enter in the following items:

  • Database Server: (server name)
  • Database Name: AdventureWorksDW2008R2
  • Name (optional): Adventure Works

For this example you can connect with the User’s Identity.  Look under the “Routines” section and you should see the stored procedures that were created above:

image

Right click on the BcsForecastReadList procedure and select “New Read List Operation”.  Keep the default settings for Operation Name and Display Name.  Below is a summary of the Read List wizard:

image image
1. Operation Properties 2. Input Parameters
image image
3. Return Parameter 4. Read List is created

Follow a similar process for the Read Item Operation.  Right-click on the BcsForecastReadItem procedure and select “New Read Item Operation”.  Below is a summary of the Read Item wizard:

image image
1. Operation Properties 2. Input Parameters
image image
3. Return Parameter 4. Read Item is created

 

You have now created your first External Content Type.  But we cannot use it yet.  In the next post I will show you how to enable security on the External Content Type and create an External List which will be displayed in the Ops Forecast site.    Below is a screen shot of the External Content Type being used as an External list:

image image
1. List View 2. View Item

 

Troy

Building BI Application’s with SharePoint 2010

 

SharePoint 2010 is an excellent Platform for creating enterprise applications that leverage your current Business Intelligence infrastructure and operational systems.  Of course your not going to build mission critical applications like POS or Supply Chain Ordering system but what about tracking weekly sales and expenses or building a pricing model that requires data from multiple data sources.    Using a combination of SharePoint 2010 and the Office 2010 products it is possible to create robust enterprise applications with a reasonable amount of effort.

Business Connectivity Services (BCS) in SharePoint 2010 and SharePoint Designer 2010 is what makes these applications possible.  Sure you could build your application using native SharePoint list but this approach is limited and does not allow you to leverage existing systems like your corporate data warehouse.    Below is a simple diagram which show how BCS allows business user’s to access external data:

image

The best way to learn about how these tools work is to work through a practical example.    Over the next few blog posts I will walk through how to create a simple sales forecasting application.   I am assuming that you have access to a desktop machine or server with at least the following software:

  • SQL Server Express 2008 R2
    • Adventure Works DW R2
  • SharePoint 2010 Foundation Server
  • SharePoint 2010 Designer

In this scenario the business users want to create a weekly forecasting model which will forecast Internet Sales by Territory by Product Category.  Execute the following to create a forecasting table in the Adventure Works DW R2 database:

select fcst.* into dbo.WeeklySalesForecast from ( select dt.CalendarYear,'Week ' + convert(nvarchar(2),dt.WeekNumberOfYear) WeekNumber , dt.MonthNumberOfYear, dt.EnglishMonthName, ter.SalesTerritoryGroup, ter.SalesTerritoryRegion, cat.EnglishProductCategoryName Category, sum(fct.OrderQuantity) LastYearQuantity, sum(fct.SalesAmount) LastYearAmount, null ForecastQuantity, null ForecastAmount from dbo.FactInternetSales fct inner join dbo.DimDate dt on fct.OrderDateKey = dt.DateKey inner join dbo.DimProduct prd on fct.ProductKey = prd.ProductKey inner join dbo.DimSalesTerritory ter on fct.SalesTerritoryKey = ter.SalesTerritoryKey inner join dbo.DimProductSubcategory sub on prd.ProductSubcategoryKey = sub.ProductSubcategoryKey inner join dbo.DimProductCategory cat on sub.ProductCategoryKey = cat.ProductCategoryKey where dt.CalendarYear = 2008 group by dt.CalendarYear,dt.WeekNumberOfYear, dt.MonthNumberOfYear, dt.EnglishMonthName, ter.SalesTerritoryGroup, ter.SalesTerritoryRegion, cat.EnglishProductCategoryName) fcst

This will create a table that can be used for building the BCS.   In this post we are going to simply create a SharePoint site using SharePoint Designer to host our SharePoint application using SharePoint Designer 2010.   Open SharePoint Designer 2010 and open the Main Site.  In my case my main site is on my laptop and can be accessed at http://localhost.  From the Site Actions menu select “New Site”:

image

 

We are now going to create a new Site called Ops Forecast (http://localhost/opsforecast) use the Team Site template:

  • Title: Ops Forecast
  • Url Name:  opsforecast

image

Now click Create and the site will be created.  In the next post we will build 2 stored procedures and create an External Content Type which will be used as a list to view the forecast data in SharePoint.

 

Troy