How to do it...

  1. Create a new console application in Visual Studio called Packt.Xrm.Batch.
  2. Right-click on References and click on Manage NuGet Packages, and search and install Microsoft.CrmSdk.XrmTooling.CoreAssembly.
  3. Include the following using statements in your .cs file:
using Microsoft.Xrm.Sdk; 
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Tooling.Connector;
  1. Copy and insert the following code in your main function (don't forget to update the connection string):
var connectionString = "AuthType=Office365;[email protected];Password=;Url=https://.crm6.dynamics.com"; 

var crmSvc = new CrmServiceClient(connectionString);

using (var serviceProxy = crmSvc.OrganizationServiceProxy)
{
//Create request collection
var request = new OrganizationRequestCollection()
{
new CreateRequest
{
Target = new Entity("account")
{
["name"] = "Packt Account"
}
},
new CreateRequest
{
Target = new Entity("contact")
{
["firstname"] = "Packt",
["lastname"] = "Contact"
}
}
};

//Create Transaction and pass previously created request collection
var requestToCreateRecords = new ExecuteMultipleRequest()
{
// Create an empty organization request collection.
Requests = request,
Settings = new ExecuteMultipleSettings()
{
ContinueOnError = true,
ReturnResponses = true
}
};

//Execute requests within the transaction
var responseForCreateRecords = (ExecuteMultipleResponse)serviceProxy.Execute(requestToCreateRecords);

// Display the results of each response.
foreach (var responseItem in responseForCreateRecords.Responses)
{
Console.WriteLine("Created record with GUID {0}", responseItem.Response.Results["id"].ToString());
}
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.134.29