web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Problem creating incident from code : customer attribute is always null

(0) ShareShare
ReportReport
Posted on by

Hi,

I'm trying to create an incident from a C3 console application, but I'm always getting the following error: 

Attribute 'customerid' cannot be NULL

I've tried using both early and late bound and XrmContext and OrganizationServiceProxy

Incident xx = new Incident() {
Title = rm.whatHappned,
OverriddenCreatedOn = rm.createdDate,
CustomerId = new CrmEntityReference(Account.EntityLogicalName, new Guid("76694771-5d2c-e511-80c6-0050568f430a"))
};


EntityReference cer = new EntityReference();
cer.Id = new Guid("76694771-5D2C-E511-80C6-0050568F430A");
cer.LogicalName = Account.EntityLogicalName;
cer.Name = "AccountName"

Entity newIncident = new Entity("incident");
newIncident.Attributes.Add("customerid", cer);
newIncident["overriddencreatedon"] = rm.createdDate;


I even tested that the attribute is not null before trying to create!

if (newIncident.Contains("customerid") && newIncident["customerid"] != null) {
service.Create(newIncident)
}
else
log("CustomerID is null"); //this one is never shown in the logs...

I was able to create an account with parent account without any problems, using the same CustomerID-GUID. 

CRM is OnPremise 2015 v.7.0.1.129.

*This post is locked for comments

I have the same question (0)
  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Problem creating incident from code : customer attribute is always null

    Hello,

    CustomerId is platform-required field and CRM would not allow you to create case without this field populated.

  • Sindre Wetting Profile Picture
    on at
    RE: Problem creating incident from code : customer attribute is always null

    Hi Andrii,

    Is anything wrong in my code? I'm setting the customerid attribute, and I've tried using a entityreference, CrmEntityreference both with early and late bound.

    Using the same EntityReference/CrmEntityRefernce I was able to create a account.

    I don't get it....

  • a33ik Profile Picture
    84,331 Most Valuable Professional on at
    RE: Problem creating incident from code : customer attribute is always null

    Try to use following code:

    Entity incident = new Entity("incident");

    incident["customerid"] = new EntityReference("account", new Guid("76694771-5D2C-E511-80C6-0050568F430A"));

    service.Create(incident);

  • Verified answer
    Sindre Wetting Profile Picture
    on at
    RE: Problem creating incident from code : customer attribute is always null

    Hi Andrii,

    It turned out to be a synchronouse workflow that caused the issue. It set the customer field based on another field. Deactivating it fixed it.

    Thanks for your time.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Problem creating incident from code : customer attribute is always null

    Have you tried this using late bound?

    Entity incident=new Entity("incident");

    incident["title"]=" Test Incident";

    incident["customerid"]=new EntityReference("account", new Guid ("76694771-5d2c-e511-80c6-0050568f430a"));

    IOrgnizationService service=new Orgnizationservice();

    service.create(incident);

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans