Hello,
I am looking for the simplest C# sample code to retrieve an entity record and value of some fields by passing the "ID" of the entity record
*This post is locked for comments
Can you help me with the code for My Active contacts under Contact entity, I want to retrieve all the records from contact entity and also update them
Can you help me with the code for My Active contacts under Contact entity, I want to retrieve all the records and also update them
aspsolutionkirit.blogspot.in/.../update-contact-entity-from-website-to.html
Retrieve a record of an entity:-
public Entity RetrieveEntityById(IOrganizationService service, string EntityLogicalname, Guid guidEntityId) { Entity entityRecord = service.Retrieve(EntityLogicalname, Entityguid, new ColumnSet(true)); return entityRecord; } public void getEntityRecord() {
Entity entity = RetrieveEntityById(service, "account", guidAccountId);
if(entity.Attributes.Contains("name")) { string strAccountName = entity.Attributes["name"] }
}
Thanks - the reply from Aileen Gusni solved the problem
Easy way,
Install this Nuget package
https://www.nuget.org/packages/CRMConnection/1.0.2
Here is the sample to connect and use the service object into your own way.
static void Main(string[] args) { Microsoft.Xrm.Sdk.IOrganizationService _service = null; Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy _serviceProxy; ServerConnection serverConnect = new ServerConnection(); // Final parameter of this method is your CRM version. like crm4, crm5 etc. If you pass Blank value it will use crm default. ServerConnection.Configuration config = serverConnect.GetServerConfiguration("yourusername", "yourpassword","crm"); _serviceProxy = ServerConnection.GetOrganizationProxy(config); // This statement is required to enable early-bound type support. _serviceProxy.EnableProxyTypes(); _service = (Microsoft.Xrm.Sdk.IOrganizationService)_serviceProxy; }
Hasibur,
Just use this:
if(entity.Attributes.Contains("new_ticketnumber"))
{
int intTickerNumber= Convert.ToInt32(entity.Attributes["new_ticketnumber"].ToString());
Aileen Gusni - thanks for your reply. How would a go about if I want to retrieve them by a custom field (i.e. - ticketnumber (int))
Thanks
Hi Hasibur:
As per your requirement, a simple sample code:
private Entity RetrieveEntityById(IOrganizationService service, string strEntityLogicalName, Guid guidEntityId)
Entity RetrievedEntityById= service.Retrieve(strEntityLogicalname, guidEntityId, newColumnSet(true)); //it will retrieve the all attrributes
return RetrievedEntityById;
How to call?
how to get the attributes?
String strAccountName = string.Empty;
if(entity.Attributes.Contains("name"))
strAccountName = entity.Attributes["name"]
msdn.microsoft.com/.../gg328416.aspx
Hope this helps.
Thanks.
Download crm sdk..it has sample code to retrieve, and for other operations.
you can download sdk from
www.microsoft.com/.../details.aspx
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 Andrés Arias as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Aric Levin - MVP 2 Moderator
MA-04060624-0 1