Question

In our CRM environment we have a custom entity type in settings for custom parameters in which entities contain a name, type, and value. I need to get one of these "parameters" in a web application using asp and C# to do some math. How might I retrieve the value and type fields of this entity in my aspx.cs file using the entity's ID so that i might make a c# variable that corresponds to the custom parameter entity.

Was it helpful?

Solution

First Way

You can connect to the CRM Web Service, which is an .asmx and retrieve your entity from there. Just add it as a web reference. From my experience adding it as a service reference is troublesome but adding as a web reference is not (since the "Add a service reference" thing is for WCF and "Add a web reference" has been there from the start for .asmx).

As an aside, if you are used to using the CRM SDK through writing plugins and custom workflow activities you may notice:

  • Under the hood, the CRM SDK assemblies are actually calling the CRM Web Service anyway...they just wrap it in a nice-ish way to faciltate the development of your plugins etc
  • Once you add the web service you'll have a whole bunch of methods to choose from and that your entities are now classes in your ASP.NET application. Because VS will import the WSDL of the service it will recognise your custom entities as first class citizens and generate the appropriate classes (i.e. you don't need to deal a lot with DynamicEntity, unlike in your plugin & custom workflow assembly development)

It is also a good practice to update/refresh your web reference if you make changes to the entities in CRM (e.g. add a field, create a new entity etc) so that your application is in sync. If you only work with a narrow set of entities (sounds like it in this case) and they don't change this isn't essential but still a good practice.

Second Way

You could get it directly out of your _MSCRM database.

If you wanted to go to the raw tables, your entity will have two tables: Base and ExtensionBase. The data you want, if it is an attribute you have defined against the entity, will be in the ExtensionBase table. There will also be an view that joins the Base and ExtensionBase table if you wanted to use that instead.

You could also query the filtered view but if you do this, you need to ensure that the account which your ASP.NET application runs as (so when deployed to IIS this will be the app pool identity) has access to CRM as going against the filtered view runs the CRM security checks against the calling user.

Also, note that going straight to the database table or the view is technically unsupported. Going against the filtered view should be OK.

I would suggest going the first way but I have seen both approaches done in the past and both should work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top