Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Retrieve attribute names from target

(0) ShareShare
ReportReport
Posted on by

How can we retrieve attribute names from target in plugin??

*This post is locked for comments

  • Verified answer
    Arun Vinoth Profile Picture
    11,615 Moderator on at
    RE: Retrieve attribute names from target

    You can try below code & modify based on your need.

    Inspired by: [View:https://stackoverflow.com/a/12403961/7920473]

    Entity targetEntity = (Entity)context.InputParameters["Target"];

    foreach (KeyValuePair<String, Object> attribute in targetEntity.Attributes)

       {

           //do something

    //Console.WriteLine(attribute.Key + ": " + attribute.Value);

       }

    Problem is you cannot write single line of code for different datatypes, and have to do null check before consuming value.

    //targetEntity.getAttributeValue<string>(“stringfield”)

    if(targetEntity.getAttributeValue<EntityReference>(“Lookupfield”) != null)

    targetEntity.getAttributeValue<EntityReference>(“Lookupfield”).Value();

    Read more:

    [View:https://community.dynamics.com/crm/f/117/t/234225]

    [View:https://community.dynamics.com/crm/b/crmchap/archive/2016/08/14/the-benefits-of-using-getattributevalue-to-access-crm-attributes-late-bound-c]

  • Verified answer
    gdas Profile Picture
    50,089 Moderator on at
    RE: Retrieve attribute names from target

    Hi,

    In addition it is very important to make sure that the fields you are looking into is available in the target.

    So be sure you are putting field name or by default is all attributes.

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/guidance/server/include-filtering-attributes-plugin-registration

    Secondly before accessing any attributes make sure you are having Contains check like below -

                            string somestring = string.Empty;
    
                            if (targetentity.Attributes.Contains("FieldName"))
                            {
                                somestring = targetentity.GetAttributeValue<string>("FieldName"); // This is form single line text
                            }
    


  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: Retrieve attribute names from target

    Hi,

    You can simply get the entity object using the below statement within the plugin

    Entity targetEntity = (Entity)context.InputParameters["Target"];

    And then you can use the below statement to get the attribute value-

    var accountName = targetEntity.GetAttributeValue<string>("name");

    If you notice in the above statement, you need to set the type (string, int, bool etc) while retrieving the attribute value.  I would recommend goig through the below blogs on the similar topic-

    community.dynamics.com/.../the-benefits-of-using-getattributevalue-to-access-crm-attributes-late-bound-c

    www.crmanswers.net/.../getattributevalue-demystified.html

    Hope this helps.

  • Suggested answer
    Adrian Begovich Profile Picture
    1,019 Super User 2025 Season 1 on at
    RE: Retrieve attribute names from target

    Hi ryou,

    There are a few ways to do this. This thread has some examples.

  • Suggested answer
    rthompson Profile Picture
    1,530 on at
    RE: Retrieve attribute names from target

    Hi ryou,

    Do you have existing plugin code.  If so,  please send a screenshot.

    Thanks

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,027 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans