Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Accessing customer attributes, added to current case

Posted on by 210

Hello. I have been developing a C# plugin for CRM 4.0. The below code runs when a new case record is created. I have been trying to access the customer's GUID (which was added to the case record which was just created), so that I can later retrieve the customer's details such as e-mail address. I have tried two ways to do this: first by accessing the Value property using target_entity.Properties["customerid"].Value and also by trying to iterate over target_entity.Properties. However, both of these returned errors (as shown below in the code).

public void Execute(IPluginExecutionContext context)
{

    DynamicEntity target_entity = null;

    target_entity = (DynamicEntity)context.InputParameters.Properties["Target"];

    / *Below line gives following error: 

    'object' does not contain a definition for 'Value' and no extension method 'Value' 
    accepting a first argument of type 'object' could be found (are you missing a using 
    directive or an assembly reference?) */

    String customerGuid = target_entity.Properties["customerid"].Value;

    /* tried alternate way to access customer GUID value by first looping 
    through each property of target_entity, then accessing the Value of the customer_id 
    key, but get following error: 

    'The type or namespace name 'PropertyValueCollection' could not be found (are you 
    missing a using directive or an assembly reference?)'

    Tried to import it with System.DirectoryServices but does not work, as 
    DirectoryServices is not recognised */

    foreach (PropertyValueCollection value in target_entity.Properties)
    {
        if (value.PropertyName == "customerid")
        {

            String customerGuid == value.Value;

        }
    }

}


*This post is locked for comments

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Accessing customer attributes, added to current case

    Hello,

    Try this:

    Guid customerGuid = ((Customer)target_entity.Properties["customerid"]).Value;

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,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans