Dynamics 365 - How to create a record using XRM Tooling

XRM Tooling is one of the options you can choose to extend Dynamics 365 and connect third party applications with Dynamics 365, using XRM Tooling there are three ways to use it,

ConnectionStrings, PowerShell cmdlets for XRM Tooling or CrmServiceClient constructors.



Note that the SOAP service will be deprecated in a future release!!, So to connect to third party applications use the XRM Tooling in the Dynamics 365 SDK

In this article I'll give an example of how to create a record using XRM Tooling,

CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["MyCRMServer"].ConnectionString);

// Verify that you are connected
if (crmSvc != null && crmSvc.IsReady)
{
    
     //inData.Add(Field Name, new CrmDataTypeWrapper(Value,Field Data Type);
    // Create an account record
    Dictionary<string, CrmDataTypeWrapper> inData = new Dictionary<string, CrmDataTypeWrapper>();
    inData.Add("name", new CrmDataTypeWrapper("Sample Account Name", CrmFieldType.String));
    inData.Add("address1_city", new CrmDataTypeWrapper("Redmond", CrmFieldType.String));
    inData.Add("telephone1", new CrmDataTypeWrapper("555-0160", CrmFieldType.String));
    //accountId = crmSvc.CreateNewRecord(Entity Name, inData);
    accountId = crmSvc.CreateNewRecord("account", inData);

    // Verify if the account is created.
    if (accountId != Guid.Empty && accountId != null)
    {
        //Record Created
    }
}
else
{
    // Display the last exception message if any.
    Console.WriteLine(crmSvc.LastCrmException.Message);
    Console.WriteLine(crmSvc.LastCrmException.Source);
    Console.WriteLine(crmSvc.LastCrmException.StackTrace);

    return;
}

Happy CRMing!

Comments

Popular Posts