web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Suggested answer
    rthompson Profile Picture
    1,532 on at

    Hi ryou,

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

    Thanks

  • Suggested answer
    Adrian Begovich Profile Picture
    1,027 Moderator on at

    Hi ryou,

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

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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
    Arun Vinoth Profile Picture
    11,615 Moderator on at

    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]

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans