Notifications
Announcements
No record found.
How can we retrieve attribute names from target in plugin??
*This post is locked for comments
Hi ryou,
Do you have existing plugin code. If so, please send a screenshot.
Thanks
There are a few ways to do this. This thread has some examples.
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.
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 }
You can try below code & modify based on your need.
Inspired by: [View:https://stackoverflow.com/a/12403961/7920473]
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.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2