Wednesday, April 20, 2011

Send Email in CRM using a Template


var xrm = new DataContext("xrm");
            Guid SalesOrderId = new Guid("AF6485A7-EA7D-DF11-A99F-001438C3D4F5");
            var xrmOrder = xrm.salesorders.Where(so => so.salesorderid == SalesOrderId).FirstOrDefault();
            var xrmCustomer = xrm.contacts.Where(co => co.contactid == xrmOrder.customerid.Value).FirstOrDefault();
            var template = (from v in xrm.templates
                            where v.title == "OrderConfirmation" && v.templatetypecode == "salesorder"
                            select v).FirstOrDefault();

            if (template != null)
            {
                using (Microsoft.Xrm.Client.Services.IOrganizationService service1 = xrm.CreateService())
                {
                    Microsoft.Crm.SdkTypeProxy.InstantiateTemplateRequest request1 = new Microsoft.Crm.SdkTypeProxy.InstantiateTemplateRequest();
                    request1.TemplateId = template.templateid;
                    request1.ObjectId = SalesOrderId;
                    request1.ObjectType = "salesorder";

                    request1.ReturnDynamicEntities = true;


                    var response1 = service1.Execute(request1) as Microsoft.Crm.SdkTypeProxy.InstantiateTemplateResponse;
                    var emailEntity = response1.BusinessEntityCollection.BusinessEntities[0] as Microsoft.Crm.Sdk.DynamicEntity;

                    var emailid = Guid.NewGuid();
                    var xrmEmail = new Entities.email(new Microsoft.Xrm.Client.CrmEntity(emailEntity,xrm));
                    xrmEmail.activityid = emailid;

                    xrmEmail.regardingobjectid = new Microsoft.Xrm.Client.CrmEntityReference("salesorder", SalesOrderId);
                    xrmEmail.to = new activityparty[] { new activityparty() { partyid = new Microsoft.Xrm.Client.CrmEntityReference("contact", xrmCustomer.contactid) } };
                    xrmEmail.from = new activityparty[] { new activityparty() { partyid = new Microsoft.Xrm.Client.CrmEntityReference("systemuser", new Guid("C4D554FE-3A5C-E011-873A-00155DF93E16")) } };
                    xrmEmail.directioncode = true;
                    xrm.AddToemails(xrmEmail);
                    xrm.SaveChanges();

                    Microsoft.Crm.SdkTypeProxy.SendEmailRequest req = new Microsoft.Crm.SdkTypeProxy.SendEmailRequest();
                    req.EmailId = emailid;//ID of created mail
                    req.TrackingToken = "";
                    req.IssueSend = true;

                    Microsoft.Crm.SdkTypeProxy.SendEmailResponse res = (Microsoft.Crm.SdkTypeProxy.SendEmailResponse)service1.Execute(req);
                }
            }

Use LINQ to Retrieve Data from Microsoft Dynamics CRM

Code Generation Using the CrmSvcUtil Tool

Monday, February 7, 2011

How to move the Microsoft Dynamics CRM 4.0 deployment

How to move the Microsoft Dynamics CRM 4.0 deployment


View products that this article applies to.



On This PageINTRODUCTION

MORE INFORMATION

Move the Microsoft Dynamics CRM databases to another SQL Server and SQL Server Reporting Services server in the same domain, and leave the Microsoft Dynamics CRM Server on the existing server

Redeploy the Microsoft Dynamics CRM deployment that includes the Microsoft Dynamics CRM Server within the same domain or to another domain.

Move the Microsoft Dynamics CRM Server or one of the Microsoft Dynamics CRM server roles. However, leave the SQL Server and the SQL Server Reporting Services server intact

Expand all
Collapse all

INTRODUCTIONThis article describes the steps that you must follow to move the Microsoft Dyna...This article describes the steps that you must follow to move the Microsoft Dynamics CRM 4.0 deployment in the following scenarios:

You want to move the Microsoft Dynamics CRM databases to another Microsoft SQL Server and Microsoft SQL Server Reporting Services server in the same domain. Additionally, you want to leave the Microsoft Dynamics CRM Server on the existing server.

You want to redeploy the Microsoft Dynamics CRM deployment that includes the Microsoft Dynamics CRM server within the same domain or to another domain.

You want to move the Microsoft Dynamics CRM Server or one of the Microsoft Dynamics CRM server roles. However, you want to leave the SQL Server and SQL Server Reporting Services server intact.

Back to the top

MORE INFORMATIONMove the Microsoft Dynamics CRM databases to another SQL Server and SQL Server R...Move the Microsoft Dynamics CRM databases to another SQL Server and SQL Server Reporting Services server in the same domain, and leave the Microsoft Dynamics CRM Server on the existing server

Back up the Organization_MSCRM database and the MSCRM_Config database. To do this, follow these steps:

On the computer that is running SQL Server, click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click SQL Server Management Studio.

Expand Databases, right-click the Organization_MSCRM database, point to Tasks, and then click Back Up.

Under Destination, add the location to save the backup file, and then click OK.

Repeat steps 1b and 1c for the MSCRM_Config database.

Note If you must move more than one organization, repeat steps 1a-1d for each organization database.

Restore the Organization_MSCRM database and the MSCRM_Config database on the new computer that is running SQL Server. To do this, follow these steps:

On the new computer, click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click SQL Server Management Studio.

Right-click Databases, and then click Restore Database.

Under Destination to restore, type the name of the Organization_MSCRM database in the To database box.

Under Source for restore, click From device, click the ellipsis button (...), add the Organization_MSCRM database, and then click OK.

Click to select the Restore check box, and then click OK.

Repeat steps 2b-2e for the MSCRM_Config database.

Note If you must move more than one organization, repeat steps 2a-2f for each organization database.

Update the following registry subkeys on the computer that is running Microsoft Dynamics CRM Server:

configdb

database

metabase

To do this, follow these steps:

On the computer that is running Microsoft Dynamics CRM Server, click Start, click Run, type regedit in the Open box, and then click OK.

Locate the following registry subkey:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM

Right-click configdb, and then click Modify.

In the Value data box, change the data source to the name of the new SQL Server, and then click OK. For example, the string value in the Value data box should resemble the following:

Data Source=NewSQLServer;Initial Catalog=MSCRM_CONFIG;Integrated Security=SSPI

Follow steps 3b-3d for the database subkey and for the metabase subkey.

Notes

If multiple Microsoft Dynamics CRM Roles are in your deployment, you must update the registry keys for all the server roles.

If you use the Microsoft Dynamics CRM Data Connector for SQL Server Reporting Services and if you are not moving the SQL Server Reporting Services server, you must update the configdb subkey on the computer on which the Microsoft Dynamics CRM Data Connector for SQL Server Reporting Services is installed.

Configure the Microsoft Dynamics CRM Application to point to the new SQL Server and SQL Server Reporting Services. To do this, follow these steps:

On the computer that is running Microsoft Dynamics CRM Server, click Start, point to All Programs, point to Microsoft Dynamics CRM, and then click Deployment Manager.

Click Organizations.

Right-click the organization that you moved to the new computer that is running SQL Server, and then click Disable.

Right-click the organization that you disabled, and then click Edit Organization.

Type the new name of the SQL Server and the new URL for the SQL Server Reporting Services server.



Note This step publishes the reports that are in Microsoft Dynamics CRM to the new computer that is running SQL Server Reporting Services server that you specify.

Click Next two times, and then click Apply.

Right-click the organization that you disabled in step 4c, click Enable, and then click Yes.

If you are using the Microsoft Dynamics CRM Data Connector for SQL Server Reporting Services and if you are moving to a new SQL Server Reporting Services server, you must install the data connector on the new computer that is running SQL Server Reporting Services.

Back to the top

Redeploy the Microsoft Dynamics CRM deployment that includes the Microsoft Dynamics CRM Server within the same domain or to another domain.

Back up the Organization_MSCRM databases. To do this, follow these steps:

On the computer that is running SQL Server, click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click SQL Server Management Studio.

Expand Databases, right-click the Organization_MSCRM database, point to Tasks, and then click Back Up.

Under Destination, add the location to save the backup file, and then click OK.

Repeat steps 1b and 1c for any other Organization_MSCRM database that must be moved.

Install Microsoft Dynamics CRM 4.0 on the new computer that will run Microsoft Dynamics CRM Server.



Note When you are prompted to enter the organization name, use a name that differs from the original organization name. You will import the old organization into the new installation. Therefore, you do not want the installation process to create a new organization that has the same name.

Restore the Organization_MSCRM databases on the new computer that is running SQL Server. To do this, follow these steps:

On the new computer that is running SQL Server, click Start, point to All Programs, point to Microsoft SQL Server 2005, and then click SQL Server Management Studio.

Right-click Databases, and then click Restore Database.

Under Destination to restore, type the name of the Organization_MSCRM database in the To database box.

Under Source for restore, click From device, click the ellipsis button (...), add the Organization_MSCRM database, and then click OK.

Click to select the Restore check box, and then click OK.

Repeat steps 3b-3e for any additional Organization_MSCRM databases.

Apply hotfix 950680.



For more information about hotfix 950680, click the following article number to view the article in the Microsoft Knowledge Base:

950680 (http://support.microsoft.com/kb/950680/ ) The workflow rules no longer run when you use the Deployment Manager Import Organization Wizard to import an organization in Microsoft Dynamics CRM 4.0

Import the organization into the new deployment of Microsoft Dynamics CRM 4.0. To do this, follow these steps:

On the new computer that is running Microsoft Dynamics CRM Server, click Start, point to All Programs, point to Microsoft Dynamics CRM, and then click Deployment Manager.

Right-click Organizations, and then click Import Organization.

If you are using the Professional edition of Microsoft Dynamics CRM, you are prompted to delete the existing organization. Click OK to delete the organization that was created during the installation.



Note This action does not delete the actual Organization_MSCRM database from the computer that is running SQL Server.

In the SQL Server box, click the computer to which you restored the Organization_MSCRM database, click the organization database in the Organization database box, and then click Next.

Type the display name and the name for the organization, and then click Next.

Type the URL in the SQL Server Reporting Services URL box, and then click Next.

Select the method in the Method for the Mapping of the Users list, and then click Next.

Map the users, and then click Next.

In the System Requirements dialog box, click Next, and then click Import.

Notes

If you plan to use the same Microsoft Dynamics CRM E-mail Router, you must run the Configuration Wizard to configure the router for the new environment.

You must install the Microsoft Dynamics CRM Data Connector for SQL Server Reporting Services to register the components with the new MSCRM_Config database.

You must run the Configuration Wizard for the Microsoft Dynamics CRM Client for Outlook to connect to the new Microsoft Dynamics CRM Server.

You must reinstall the Data Migration Manager to point to the new Microsoft Dynamics CRM Server.

Back to the top

Move the Microsoft Dynamics CRM Server or one of the Microsoft Dynamics CRM server roles. However, leave the SQL Server and the SQL Server Reporting Services server intact

Install the Microsoft Dynamics CRM Server or server role on a new server. To do this, follow these steps:

On the new computer, install Microsoft Dynamics CRM Server.

During the installation process, type the name of the SQL Server on which the MSCRM_Config database exists in the Select Deployment Options dialog box, and then click Connect to an Existing Deployment.

Complete the installation.

Uninstall the Microsoft Dynamics CRM Server or the server role from the old Microsoft Dynamics CRM Server. To do this, follow these steps:

In Control Panel, open the Add or Remove Programs item.

Select the Microsoft Dynamics CRM Server, and then click Change/Remove.

Complete the removal wizard to remove the Microsoft Dynamics CRM Server or server role on the old server.

Note If you cannot uninstall the old Microsoft Dynamics CRM Server or server role in step 2 because of a hardware failure, go to step 3.

Remove the server from Deployment Manager. To do this, follow these steps:

On the computer that is running Microsoft Dynamics CRM Server, click Start, point to All Programs, point to Microsoft Dynamics CRM, and then click Deployment Manager.

Click Servers. A list of the servers in the Microsoft Dynamics CRM deployment should appear. If no servers appear, right-click Servers, and then click Refresh.

Right-click the server that is not in the deployment, click Delete, and then click Yes. The server is removed from the MSCRM_Config database.

Note Depending on the Microsoft Dynamics CRM roles that you move, you may have to run the Configuration Wizard for the Microsoft Dynamics CRM E-mail Router to update the configuration. You may also have to run the Configuration Wizard for the Microsoft Dynamics CRM Client for Outlook to connect to the new Microsoft Dynamics CRM Server. Additionally, you may have to reinstall the Data Migration Manager to point to the new Microsoft Dynamics CRM Server.

Back to the top

Note This is a "FAST PUBLISH" article created directly from within the Microsoft support organization. The information contained herein is provided as-is in response to emerging issues. As a result of the speed in making it available, the materials may include typographical errors and may be revised at any time without notice. See Terms of Use (http://go.microsoft.com/fwlink/?LinkId=151500) for other considerations.