cancel
Showing results for 
Search instead for 
Did you mean: 

Support of non-default statecode in CreateRequest and UpsertRequest

Author Name: Daniel Cai

With the introduction of new API capabilities in CRM 2015 Update 1 release, we now support special CRM fields (such as statecode, ownerid, etc.) in UpdateRequest without requiring an extra service call as it used to, this is a great enhancement.

However, the same capability should have been brought to CreateRequest and UpsertRequest as well to help improve data migration/integration performance, as it would save a service call by enabling creating inactive (or any non-default statecode) records, which is unfortunately not the case. If we try to create or an inactive (or any non-default statecode/statuscode combination) record using CreateRequest (or UpsertRequest), CRM will throw an exception, such as the following one.

2 is not a valid status code for state code AccountState.Active on account with Id e853a8fc-a5fe-e411-80d5-fc15b428f658.

The following is my code snippet using UpsertRequest (The error only happens when it is a new record).

using (var service = new OrganizationService(crmConnection))
{
// Use alternate key (accountnumber) field to identify an account record
var account = new Entity("account")
{
KeyAttributes = new KeyAttributeCollection
{
{"accountnumber", "ACT-12345" }
}
};

account["name"] = "KingswaySoft";
account["creditlimit"] = new Money(100000);
account["statecode"] = new OptionSetValue(1);
account["statuscode"] = new OptionSetValue(2);

var request = new UpsertRequest { Target = account };
var response = (UpsertResponse)service.Execute(request);
}

Status: Planned

Thank you for your feedback. This is a great suggestion! We will consider this in our roadmap.

 

Sincerely,

Neeraj Nandwana

PM, Microsoft 

Support of non-default statecode in CreateRequest and UpsertRequest

Comments
D365Ideas_Admin
Regular Visitor
Status changed to: Planned

Thank you for your feedback. This is a great suggestion! We will consider this in our roadmap.

 

Sincerely,

Neeraj Nandwana

PM, Microsoft 

Support of non-default statecode in CreateRequest and UpsertRequest