Mohammed Atef’s Technical blog

How to Setup Microsoft Dynamics CRM for Outlook

One of the most Important features for Microsoft CRM Dynamic 4.0 is integration with Microsoft Office Outlook to do this just follow the following steps

1- Go to you CRM Install Package and copy the client folder into your client machine

2- run the setup file named SetupClient.exe

3- make sure you have installed the .net framework 3.0 or later and Microsoft Visual c++ runtime 8.0 or later.

4- important note the i have write this post for it

if you do not have Microsoft Visual C++ runtime installed download it and put it in folder named VcRedist then copy this folder beside the EXE file mention in step 2

5- after the installation finished go to Microsoft Office Outlook you will find big link in the top of you personal outlook named configure CRM Dynamic just click this link and follow the wizard till you finish.

6- now you can find all activities you authorized to access from Microsoft Dynamics SRM 4.0 available into you Microsoft Office Outlook….. Good Luck.

I hope this help.


July 29, 2009 Posted by | CRM Dynamics 4.0 | , , | Leave a comment

Call Microsoft Dynamics CRM Web Services

did you ever tried to call MS CRM Dynamics web service before? It is very simple but you must be familiar with JavaScript.  

Generate the CRM Header

It is possible to access the Microsoft Dynamics CRM Web services from your client-side JScript code.

The most efficient way to access Microsoft Dynamics CRM Web services is to create a Web service on the computer running Microsoft Dynamics CRM and connect to it from your client-side JScript code.

In Microsoft Dynamics CRM Online you cannot create a Web service application on the server so you must use XMLHttp requests to the Microsoft Dynamics CRM Web services.

The  GenerateAuthenticationHeader  function retrieves a properly formed Microsoft Dynamics CRM authentication header. This authentication header automatically determines the appropriate authentication type to use for each deployment type: on-premise, IFD, or Microsoft Dynamics CRM Online. Note that the SOAP header for IFD does not include information about the CrmTicket because a session-based ticketing system is used


You can generate this header for your code by using the following function:


Without this function you would need to define a SOAP header in your code like the one here for the on-premise version:


  <CrmAuthenticationToken xmlns=>

    <AuthenticationType xmlns=>



    <OrganizationName xmlns=>



    <CallerId xmlns=>





Call CRM web service

After generating the header you can use it as shown in the below code

//Prepare variables for a contact to retrieve.

var contactid = “4696f8cb-9a1c-dd11-ad3a-0003ff9ee217”;

var authenticationHeader = GenerateAuthenticationHeader();


//Prepare the SOAP message.

var xml = “<?xml version=’1.0′ encoding=’utf-8′?>”+

“<soap:Envelope xmlns:soap=’'&#8221;+

” xmlns:xsi=’'&#8221;+

” xmlns:xsd=’’>&#8221;+



“<Retrieve xmlns=’’>&#8221;+



“<columnSet xmlns:q1=’; xsi:type=’q1:ColumnSet’>”+








//Prepare the xmlHttpObject and send the request.

var xHReq = new ActiveXObject(“Msxml2.XMLHTTP”);

xHReq.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);


xHReq.setRequestHeader(“Content-Type”, “text/xml; charset=utf8”);

xHReq.setRequestHeader(“Content-Length”, xml.length);


//Capture the result.

var resultXml = xHReq.responseXML;

//Check for errors.

var errorCount = resultXml.selectNodes(‘//error’).length;

if (errorCount != 0)


     var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue;



//Display the retrieved value.



I hope this help.

April 30, 2009 Posted by | CRM Dynamics 4.0 | , , | Leave a comment

CRM Dynamics 4.0 Work Flow

One important consideration is that Workflows in Microsoft Dynamics CRM are executed asynchronously, and use a Windows service to act as a Host application for the Workflow engine to work. This Windows service is called the Microsoft CRM Asynchronous Processing Service and must be running on the server or else the Workflows won’t execute. Notice that if this service is not running, you won’t see any of the Workflows you created. However, they will run as soon as you start this service because they are queued.

By default, any valid CRM user can create Workflows; however, the permissions to create Workflows can be configured by roles, to prevent users from creating new Workflows that might corrupt the system data.

Workflow Events

Workflow Manager include additional triggering events and run settings.
The events that trigger a Workflow are:
* Record is created  * Record status changes
* Record is assigned * Record attributes change * Record is deleted

Workflow Scope

Workflows created through this interface can be applied to the following areas:
* Users * Business units * Parent: Child business units * Organization

Exporting and Importing Workflows

You can transfer Workflows from one organization to another by exporting them as compressed zip files and then importing them into the new system.


To export a Workflow, navigate to Settings, Customization, Export Customizations. Select Workflows from the View drop-down menu
You can export all Workflows by clicking on More Actions and selecting Export All Customizations or export only the selected Workflows.
The Workflow is downloaded as a compressed zip file. Inside the compressed zip file resides an XML file named customizations.xml.


To import a Workflow, follow these steps:
1- Go to Settings, Customization, Import Customizations
2- Enter the local path of the customization file or click the Browse button to locate the customized Workflow file on your hard disk. Click Upload to continue.

Creating Workflows in Windows Workflow Foundation (WWF) with Visual Studio

we can use work flow with Microsoft CRM Dynamics without writing any number of line code

No-Code Workflow

The CRM 4.0 SDK comes with a new Visual Studio project template to build No-Code Workflows. These No-Code Workflows are Extensible Object Markup Language (XOML) files—they contain Workflow markup in XML format.
The advantages of No-Code Workflows include the following:
* Can be deployed without compiling * Easier to develop
* Can be deployed on live CRM servers or on-premise servers
* Can share WWF activities by adding parallel tasks or loop/while conditions
Before being able to create a No-Code Workflow, you need to install the CRM Workflow project templates. To install these templates, follow these steps:
1- Locate the solution file with the name WorkflowConfigurationTool.sln in the SDK folder\Tools and open the solution file with Visual Studio 2005.
2- Add the missing references Microsoft.Crm.Sdk.dll and Microsoft.Crm.SdkTypeProxy.dll to the CrmWorkflowConfigurationAndDeployment project.
3- Update the web references for the two Web Services and change the compilation mode to release then build the entire solution.
4- Close Visual Studio, go to the SDK\Tools\DeployWorkflowTool\Release folder and execute the setup.exe, click next to confirm installation, click next to continue.
Now you can start Visual Studio 2005 and start creating CRM Workflow assemblies. From Visual Studio, go to File, New, and Project. Expand Visual C# node, click CRM node, and select CRM 4.0 Workflow.
When you create a new project using this template, you will see a new group of activities specially designed to be used with CRM
Note, If you don’t see these activities in the toolbox, right-click the General Tab and click the Choose Items menu option. Then browse and add the Microsoft.Crm.Sdk.dll, which is located in the SDK\bin folder.
To configure and deploy these Workflows, you must install a Visual Studio add-in that comes with the CRM SDK. The add-in installer filename is DeployAddin.msi. Install it by double-clicking the file and following the installation procedure.
The following example shows how to build a Workflow that will create a Phone Call activity for every new Contact added to CRM.
To create the sample, you first must perform the following configuration tasks.


Go to the Tools menu in Visual Studio and select the Microsoft Dynamics CRM menu option, Configure Workflow
1- The first screen asks you to choose whether you want to configure the deployment for CRM live or an on-premise CRM server
2- Select the On-Premise option and enter the CRM server address, username, password, and Windows domain name
3- Select the organization where you want to deploy the Workflow then enter a name for the Workflow
4- In the General section, locate the XOML Workflow filename on your hard disk by clicking Browse
5- Move to the Primary Entity selection in the list box and click Update List because all the entity types might not show by default.
6- Select the entity you want to associate the Workflow with. For this example, we use the Contact entity ,In SDK Events, check the Create option
7- Move to local parameters and enter NewContactWelcomePhoneCall as the Parameter name and select the Microsoft.Crm.Sdk.DynamicEntity in the Type Name drop-down box. Then click Add You can create any properties you need here.
8- Click Save and Close.


To develop the Workflow, follow these steps
1- Select the Policy activity, which is under the Windows Workflow section in the toolbox, and drag it into the CrmWorkflow1.xoml file or double-click the item and it will be automatically added.
2- Go to the Properties window and select the RuleSetReference property; then click the … button,Click the New button ,Click the Add Rule button and In the Condition section, enter true
3- In the Then section, enter the following code:

   1: this._NewContactWelcomePhoneCall =Microsoft.Crm.Workflow.CrmWorkflow.CreateEntity("phonecall")
   2: this._NewContactWelcomePhoneCall["subject"] = "Call this new contact"

4- Click OK to close the Rule Set Editor. And Click OK to close the RuleSetReference dialog box.

5- Select the CreateActivity item that is in the toolbox under the General group, drag this activity to the Workflow under the PolicyActivity you added in step 1, and go to the properties window.

If you don’t see these activities in the toolbox, right-click the General Tab and click the Choose Items menu option. Then browse and add the Microsoft.Crm.Sdk.dll which is located in the SDK\bin folder

6- Select the Entity property and click on the … button.

7- Select the NewContactWelcomePhoneCall property and Click OK to continue and Save WorkFlow at the end The resulting Workflow should look similar to this figure



1- Go to the Tools menu in Visual Studio and select the Microsoft Dynamics CRM menu option, followed by Configure Workflow.

2- Click the Deploy button and click Yes to continue and To publish the Workflow click Yes

3- Click OK to continue and Click Save and Close

To see the Workflow that was just deployed, open Internet Explorer and go to the CRM web interface. Go to Settings and then to Workflows.

You can also see the deployed Workflows and publish or unpublish them from Visual Studio. Go to the Tools menu, select the Microsoft Dynamics CRM menu option, and then select Manage Workflows.

Custom Workflow Activities

Custom workflow activities are used to build workflow with code behind using WWF. The difference between them and No-Code workflows that we reviewed previously is that custom workflow activities are compiled in dynamic link libraries (DLL) and can be used from the Workflow interface found in either the Web or Outlook client applications as new steps. To create a custom workflow activity, open Visual Studio 2005 and create a new project using the Workflow Activity Library template that is inside the Visual C#, Workflow project.

After creating the project, you will have to add the references for microsoft.crm.sdk.dll and microsoft.crm.sdktypeproxy.dll.

With this project, you can add any workflow activity from the toolbox as well as add code in C# in the code behind if desired. For our example, we use the same sample we used for the No-Code workflow but this time with a custom activity. Go to see the code behind and replace any existing code with the following:

   1: using System;
   2: using System.ComponentModel;
   3: using System.ComponentModel.Design;
   4: using System.Collections;
   5: using System.Drawing;
   6: using System.Workflow.ComponentModel.Compiler;
   7: using System.Workflow.ComponentModel.Serialization;
   8: using System.Workflow.ComponentModel;
   9: using System.Workflow.ComponentModel.Design;
  10: using System.Workflow.Runtime;
  11: using System.Workflow.Activities;
  12: using System.Workflow.Activities.Rules;
  13: using Microsoft.Crm.Workflow;
  14: using Microsoft.Crm.Sdk;
  16: namespace CustomActivityLibrary
  17: {
  18:     [CrmWorkflowActivity("Custom Activity", "Custom Activities Library")]
  19:     public partial class CustomActivity : SequenceActivity
  20:     {
  21:         public CustomActivity()
  22:         {
  23:             InitializeComponent();
  24:         }
  25:         public static DependencyProperty myContactProperty =
  26: DependencyProperty.Register("myContact", typeof(Lookup), typeof(CustomActivity));
  28:         [CrmInput("My contact")]
  29:         [CrmReferenceTarget("contact")]
  30:         public Lookup myContact
  31:         {
  32:             get
  33:             {
  34:                 return (Lookup)base.GetValue(myContactProperty);
  35:             }
  36:             set
  37:             {
  38:                 base.SetValue(myContactProperty, value);
  39:             }
  40:         }
  41:         protected override ActivityExecutionStatus Execute(
  42:                                        ActivityExecutionContext executionContext)
  43:         {
  44:             // Get the context service.
  45:             IContextService contextService =
  46:                 (IContextService)executionContext.GetService(typeof(IContextService));
  48:             IWorkflowContext context = contextService.Context;
  50:             // Use the context service to create an instance of CrmService.
  51:             ICrmService crmService = context.CreateCrmService();
  53:             // Creates the Phone Call activity for this conatct
  54:             Microsoft.Crm.SdkTypeProxy.phonecall nyPhoneCall =
  55:                                new Microsoft.Crm.SdkTypeProxy.phonecall();
  56:             nyPhoneCall.subject = "Call this new contact";
  57:             nyPhoneCall.regardingobjectid = myContact;
  58:             crmService.Create(nyPhoneCall);
  59:             return ActivityExecutionStatus.Closed;
  60:         }
  61:     }
  62: }

Build the solution in debug mode to create the assembly.

To deploy the custom workflow activities, register the compiled assembly as a Plug-In using the same plugindeveloper tool we used in, with minor changes to the register.xml file. Here is an example of how the register.xml file should look for our sample:

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <Register
   3:     LogFile = "Plug-in Registration Log.txt"
   4:     Server  = "http://crm4"
   5:     Org     = "Webfortis"
   6:     Domain  = "Webfortis"
   7:     UserName= "administrator" >
   9:         <Solution SourceType="0" Assembly="C:\CRM4 book\Chapter 20\CustomActivityLibrary\CustomActivityLibrary\bin\Debug\CustomActivityLibrary.dll">
  10:                 <WorkflowTypes>
  11:                         <WorkflowType TypeName="CustomActivityLibrary.CustomActivity" FriendlyName="Custom Activity"/>
  12:                 </WorkflowTypes>
  13:         </Solution>
  14: </Register>

After deploying the custom workflow activity, you can use it on any Workflow. To do this, go to Settings, Workflow, and click New. Enter a name for the workflow and select Contact in the Entity. Click OK to move to the next step. Then click Add Step and you will see the new group called Custom Activities Library with our Custom Activity inside .

Add a step with the Custom Activity and click the Set Properties button.You can set any custom property you added on the code. Our example sets the My Contact property we used to send the current contact where the workflow will be running Click Save, Close to close the Set Custom Step Input Properties and then click Save to save the workflow. Click Publish to test this solution.

important note,You can install custom workflow activities on On-Premise servers only, because they are not supported by CRM Live servers.

February 5, 2009 Posted by | CRM Dynamics 4.0, MS Dynamics | , , | 6 Comments