Tuesday, April 8, 2014

SSIS Script Task using KingswaySoft for CRM 2011

Hi Guys,
kingswaysoft components allow simple operations like Retrieve, Update or Create, but when you need to do something more complex, there is no kingswaysoft components. But kingswaysoft provides two useful assemblies that you can uses them in a Script Task:
  • KingswaySoft.DynamicsCrmServices
  • KingswaySoft.IntegrationToolkit.DynamicsCrm
To do it follow this short toturial:
You need to create a Script Task in your Data Flow Process.
And to add your kingswaysoft crm connection manager to Connection Managers List:

After that you should to add kingswaysoft assemblies in reference like this :
Then, You should add kingswaysoft namespaces like this:

  1. #region Namespaces
  2. using System;
  3. using System.Data;
  4. using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  5. using Microsoft.SqlServer.Dts.Runtime.Wrapper;
  6. using System.ServiceModel.Description;
  7. using KingswaySoft.IntegrationToolkit.DynamicsCrm;
  8. using KingswaySoft.DynamicsCrmServices.Soap2011;
  9. using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.Query;
  10. using KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService;
  11. #endregion
So, Now you need to create a IOrganizationService Object
  1. [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
  2. public class ScriptMain : UserComponent
  3. {
  4.  
  5.     KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.IOrganizationService orgService;
  6.     ...

In PreExecute Methode, intialize your IOrganizationService Object using the AcquireConnection methode:

  1. public override void PreExecute()
  2. {
  3.     base.PreExecute();
  4.     var conn = (CrmConnection)Connections.CrmConnection.AcquireConnection(null);
  5.  
  6.     orgService = (KingswaySoft.DynamicsCrmServices.Soap2011.OrganizationService.IOrganizationService)conn.GetCrmService();
  7.     
  8. }
After that you can use all needed methods like RetrieveMultiple, Execute, Update etc...
Good Luck

N.JL

3 comments:

  1. The script above will not work in SQL 2005 or 2008 because it requires .NET 4.0 . For a better alternative, check COZYROC SSIS+ library which has its own CRM backend which doesn't require .NET 4.0 . In addition COZYROC provides reusable scripts technology not found anywhere else.

    ReplyDelete
  2. Hi Nizar,

    Thanks for provide such article to use ms CRM connection in to the script component. But unable to find the above mentioned assembly name "KingswaySoft.IntegrationToolkit.DynamicsCrm.dll". Can you please help me for that?
    Thanks.

    ReplyDelete
  3. I did exactly what is mentioned here. unfortunately when I put a debug point on this it never hits and neither does any work.

    ReplyDelete