Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to check customer type within Case

Posted on by Microsoft Employee

Hi, 

In Case, there is a field  called "Customer". This field is unique, because we can choose between contact or account. 

I created a plugin to move new case to inactive state, if the customer email is match with condition. Here the code:

if (entity.Attributes.Contains("customerid"))
                {
                    Entity customer_detail = _service.Retrieve("contact", ((EntityReference)entity["customerid"]).Id, new ColumnSet(true));
                    
// Code to move case to inactive. 

}


The problem is, when user is choose  Account not contact, of course my plugin will throw an error because the contact is not found. The question is, how to check if the customer field contains account or contact ?

*This post is locked for comments

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: How to check customer type within Case

    H Fikri,

    Please modify the code as shown below.

     if (entity.Attributes.Contains("customerid"))
                {
                    Entity customer_detail = _service.Retrieve(((EntityReference)entity["customerid"]).LogicalName, ((EntityReference)entity["customerid"]).Id, new ColumnSet(true));
    
                    // Code to move case to inactive. 
    
                }

    Hope this helps.

  • Verified answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: How to check customer type within Case

    You can simply change your code like follow:

    if(entity.Contains("customerid"))

    {

    Entity customer_detail = _service.Retrieve(entity.GetAttributeValue<EnityReference>("customerid").LogicalName,entity.GetAttributeValue<EnityReference>("customerid").Id, new ColumnSet(true));

    }

    LogicalName

  • Verified answer
    Iswarya Profile Picture
    Iswarya 1,345 on at
    RE: How to check customer type within Case

    Hi,

    try this

    if (entity.Attributes.Contains("customerid") && entity.Attributes["customerid"]!=null)

                   {

    EntityReference CustomerRef = (EntityReference)entity.Attributes["customerid"];

                       Guid CustomerId = CustomerRef.Id;

                       Entity customer_detail = _service.Retrieve("contact", CustomerId, new ColumnSet(true));

    // Code to move case to inactive.

    }

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How to check customer type within Case

    ((EntityReference)entity["customerid"]).LogicalName

    Refer this:

    http://www.crmanswers.net/2014/08/dynamics-crm-special-data-types.html

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans