Home » Microsoft Technologies

Dynamic Entity-Create Entities in CRM


                   I had created a dynamic entity and properties to it by using



na = newDynamicEntity();

na.Name =



StringProperty MyAccountName = newStringProperty();

MyAccountName.Name =


MyAccountName.Value =



newProperty[] { MyAccountName};


StringProperty MyAccountNo = newStringProperty();

MyAccountNo.Name =


MyAccountNo.Value =


na.Properties= newProperty[] { MyAccountNo};

                      when doing like this, only the last added propety is created in CRM( here, only accountnumber is saved in CRM)..I want to create an account  with the name 'Greg' and account number '1234596'...I can use

na.Properties= newProperty[] { MyAccountName,MyAccountNo};

But ,is there is any other alternative to do this?


19 Answers Found


Answer 1


first you need to decide you will use crmwebservice or crm  SDK for that.


Answer 2

Try to use easiest code:

DynamicEntity na = new DynamicEntity("account");

na["name"] = "Greg";

na["accountnumber"] = "123456";


Answer 3

Working with dynamic  entities is a bit different in 4.0 vs. 3.0.  When writing plug-ins and using Microsoft.Crm.Sdk, you have the ability to access the attributes of a Dynamic Entity via a property bag, much like this:

DynamicEntity updateEntity = new DynamicEntity("m3_roundrobin"); updateEntity["m3_lastuserid"] = newOwner.ToString(); updateEntity["m3_teamid"] = teamId.ToString();

However, if you're writing an application that used the standard crm  web service, this methodology is not available to you, so you have to resort to the more code-intensive methods we used in CRM 3.0

Fortunately, if you look deep into the CRM SDK, you'll find a solution to this issue.

After installing the CRM 4.0 SDK, browse to this folder:


and look for the following file:


If you add this file to your Visual Studio project, you will have the same Dynamic Entity property bag capability using the CRM web service as you do when using the Microsoft.Crm.Sdk assembly.

I was pleasantly surprised when I located the code and it has made working with Dynamic entities  much easier.


Source : https://community.dynamics.com/blogs/billoncrm/comments/61642.aspx


Answer 4

I had found 'dynamicentitypartialtype.cs' in  CRM 4.0 SDK..How can I add this file to my project?


Answer 5

rightclick on solution explorer, select Add existing item and browse dynamicentitypartialtype.cs file and click on add

Answer 6

But, In SDK, There is only the name  'dynamicentitypartialtype.cs'   and a description, I did not find a .cs..Pls help me



Answer 7

I think you are looking for a code with less lines.

This code does exactly the same as your example:


DynamicEntityna = newDynamicEntity("account");

na.Properties.Add(new StringProperty("name", "Greg"));

na.Properties.Add(new StringProperty("accountnumber", "1234596"));


Dejan Dular

Microsoft Certified Business Management Solutions Specialist

Answer 8

Hmmm, you will get this file under "sdk\server\helpers\cs\crmhelpers" location

Answer 9

I have CRM 4.0 installed in my machine and a CRM SDK 4.0.chm file..Is this is enough to find the file 'dynamicentitypartialtype.cs'?



Answer 10

DynamicEntityna = newDynamicEntity("account");

na.Properties.Add(new StringProperty("name", "Greg"));

na.Properties.Add(new StringProperty("accountnumber", "1234596"));

            This was not working in my page..(.Add) is not recognized..Also na["name"] is not recognized..I am using CRM web services.

              Why this happen?..Is there is any way to make it recognize?..(other than to install Crm 4.0 sdk and include 'dynamicentitypartialtype.cs')..pls help me..


Answer 11

Have you referenced microsoft.crm.sdk.dll and microsoft.crm.sdktypeproxy.dll?

Also check if your project is set to .net framework 3.5. Maybe this is an issue too.


Answer 12

Hey ,

When you will install crm  SDK, it will create a SDK folder , Under that you should get server\helpers\cs\crmhelpersdynamicentitypartialtype.cs  file


Answer 13

I had referenced to both microsoft.crm.sdk.dll and microsoft.crm.sdktypeproxy.dll..



                              But,still there is problem..How can I check my  project is set to .net framework 3.5?..


Answer 14

Is there is any solution to the problem without using dynamicentitypartialtype.cs  ?.   I am using Crm web services . dynamic  Entity is recognized in my page..But,Properties do not have the attribute Add.

 So, I can't use

DynamicEntityna = newDynamicEntity("account");

na.Properties.Add(new StringProperty("name", "Greg"));

na.Properties.Add(new StringProperty("accountnumber", "1234596"));


na["name"] = "Greg";

na["accountnumber"] = "123456";


                For, make use of the above codes, what can I do? pls help me 



Answer 15

dynamicentitypartialtype.cs is when you want to use crmservice reference, so other way is to use only MS crm  SDK, remove crm webservice reference and use only MS CRM SDK then you should be able to use like below

DynamicEntity _account = new DynamicEntity("account");



Answer 16

I am using Crm web service..So, I think the above dlls are not required..I need a solution for Dynamic Entity in Crm web service..pls help me keeping this in mind...What I actually want is an alternative to

na.Properties =

newProperty[] {MyAccountno,MyaccountName}

                       Bcoz, I want to avoid 'comma'...


Answer 17

Hi Hari,

You can not use the above code when you are working with MS crm  Web Service.

Use below code:



na = newDynamicEntity();




StringProperty accountName = newStringProperty();






StringProperty accountnumber = newStringProperty();






newProperty[] { accountName, accountnumber};



Thanks, Ranjitsingh R | http://mscrm-developer.blogspot.com/ | MS CRM Consultant

na.Properties =

accountnumber.Value =

accountnumber.Name =


accountName.Value =

accountName.Name =



na.Name =


Answer 18

Ranjit he has already mentioned he don't want to use this approach  :)

na.Properties =


newProperty[] { accountName, accountnumber};

Hari : I am not getting you why you are not able to add this file, if you are not getting this file I will suggest you to download CRM SDK and install and get this file



Answer 19

Thank you all,especially Mahain

                                         I think, and now got an alternative..which is ,

na.Properties =


   So,by incrementing 'i', I am able to enter both the properties

if i=0;

 na.Properties[i] = MyAccountName;

if i=1;

na.Properties[i] = MyAccountNo;

                                      The problem is fixed.



i've created a new entity in the crm linked with contact entity, a new module, adding date and informations...

My problem is, its working fine with new contact but old one .. the date is wrong.. and I don't know how to debug this?

Thanks a lot,



Hi Friends,

                  I want to retreive and update dynamic entity in crm..For retrieving, I tried the following code

         // Create the retrieve target.
            TargetRetrieveDynamic targetRetrieve = new TargetRetrieveDynamic();

            // Set the properties of the target.
            targetRetrieve.EntityName = EntityName.contact.ToString();
            targetRetrieve.EntityId = created.id;

            // Create the request object.
            RetrieveRequest retrieve = new RetrieveRequest();

            // Set the properties of the request object.
            retrieve.Target = targetRetrieve;
            // Be aware that using AllColumns may adversely affect
            // performance and cause unwanted cascading in subsequent
            // updates. A best practice is to retrieve the least amount of
            // data required.
            retrieve.ColumnSet = new AllColumns();

            // Indicate that the BusinessEntity should be retrieved as a DynamicEntity.
            retrieve.ReturnDynamicEntities = true;

            // Execute the request.
            RetrieveResponse retrieved = (RetrieveResponse) service.Execute(retrieve);

            // Extract the DynamicEntity from the request.
            DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntity;

                          But there is an error in the following line

  targetRetrieve.EntityId = created.id;

                                "the name 'created' does not exist in the current context"...Why this happen? I am using crm web services(not sdk)..How can I specify the entity id?..ppls help me to do this



Our client has a custom entity called purchase order and a child called purchase order product (not linked to the standard product entity in Dynamics). I have written a few easy quote templates in my time, but i am slightly stuck writing a custom report template (apologies in advance if this is something simple i have missed..).

I have created 2 rdl files, one called 'order', one called 'sub'.

On the 'Sub' report i have done the following:

1. created a dataset called sub with the following query

SELECT        dhc_purchaseorderid, dhc_total1, dhc_quantity1, dhc_unitcost1, dhc_name
FROM            FilteredDhc_purchaseorderproduct
WHERE        (dhc_purchaseorderid = @dhc_purchaseorderid)

2. Created a parameter called 'dhc_purchaseorderid', with a prompt called 'report_parameter_0' and a datatype of Text. Allow blank values and remain hidden.

On the 'order' report i have done the following:

1. Created a dataset called CRM with the following query

select dhc_purchaseorderid from filtereddhc_purchaseorder 

2. Added the 'sub' report to the order report and called it details, and chose my sub report. Then added a parameter



When i try running or displaying the report i get the following error:

------ Build started: Project: Report Project5, Configuration: Debug ------

[rsCompilerErrorInCode] There is an error on line 0 of custom code: [BC30037] Character is not valid.

Build complete -- 1 errors, 0 warnings

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

I am fairly new to SSRS - so i am likely to be missing something obvious...

Any help appreciated.



Hi Friends,

                     I want to create an order entity in CRM..For that I used the following code

                DynamicEntity n1 = new DynamicEntity();
                n1.Name = "salesorder";

                StringProperty sp1 = new StringProperty();
                sp1.Name = "ordernumber";
                sp1.Value = "126";
                 StringProperty sp2 = new StringProperty();
                sp2.Name = "name";
                sp2.Value = "pens";
                CustomerProperty sp3 = new CustomerProperty();
                sp3.Name = "customerid";
                sp3.Value = new Customer();
                sp3.Value.type = "account";
                sp3.Value.Value = new Guid("F0C9AD12-AC82-DF11-A5BF-0003FF310250");

                 n1.Properties = new Property[]{sp1 ,sp2};
                TargetCreateDynamic myTarget = new TargetCreateDynamic();
               myTarget.Entity = n1;
               CreateRequest create = new CreateRequest();
              create.Target = myTarget;
              CreateResponse myResponse = (CreateResponse)service.Execute(create);

                    When running this, "customer not specified "  exception arises..Is this code correct?..Is this one enough for creating a new order in CRM?..

                    Thanks in advance..


Hi, Friends,

                     I want to map the attributes of CRM and GP entities..I want to find the entities in GP corresponds to Account, Order and Product..Pls help me to do that


I have an event form. The event has existing   3 to 4 trips.

When ever I click on new event tab, the existing Trips  should be populated in a datagrid.

I have an event entity and Trip Entity

How to do this using crm grid?


I am using MS CRM 4 and have created two custom entities (supplier and Items) each supplier can have many items assigned to it. I have further created a 1:n relationship to facilitate this.

The problem is when a user mistakenly assignes a wrong item(s) to a supplier and then decides to delete it/them he ends up deleting the item(s) in a cascade manner. Hence rather than a link between supplier and item(s) being removed the item itself is deleted form the Items list along with all other suppliers item is associated with,

I have set the relationship behaviour of 1:n to Referential where delete is set to 'remove link' but this does not work as expected.

Can you please advise how I can set-up the entities to remove the link rather then delete the item.

I am using Dynamics CRM 4.0 and SDK. I have test:
- Customize 1 new Entity, and using SDK to add new records for this entity - it is OK
- I am using SKD to add a new record for Product Entity - it is OK
- I customize Product Entity by add some of field into Product Entity - I cannot add new record in this case.

Do you have any experiences on this? (Cannot add new record for Customize Dynamics CRM Entity from SKD)

Is it limitation from SDK?

Thanks in advance.


In plugin I have retrieved the base currency value from a field and I like to use that value to update the base currency on a related entity. I'm not getting any errors but the value is not saved in the database and also does not show on the related entity form. What am I doing wrong here?

DynamicEntity d = new DynamicEntity();

d.Name = EntityName.account.ToString();

d.Properties.Add(new KeyProperty("accountid", new Key(accountid)));

d.Properties.Add(new CrmMoneyProperty("cit_linakdynamicbudget_base", new CrmMoney(linakdynamicbudgetsum)));


TargetUpdateDynamic target = new TargetUpdateDynamic();

target.Entity = d;

UpdateRequest request = new UpdateRequest();

request.Target = target;





I am wanting to create a custom history entity that will hold inactive records from another entity but am wanting to achieve this on 3 different entities.

do you know a way to achieve this?

all help is appricated.


Hi All,

When I add new entity on CRM 3, there is some errors occur : "An Error has occurred. For your information, contact your system administrator.", it also appears when i add/edit/remove attribute from some custom entity (not all entity, for some others, it just work well).

Does anybody face this problem before?

how can i solve it?

fyi, i'm googling before about this situation, and found this link

"http://support.microsoft.com/kb/934690" i followed the solution, but it just not worked.

thx before for your helps.




Hi Friends,

                I am trying to create a dynamic entity in CRM..The following code works correctly for 'account' entity.But, for 'product entity' ,the attempt was not successful..Why this happen?..pls correct the error and help me to create a product entity.


DynamicEntity n1 = newDynamicEntity();

n1.Name =



StringProperty sp = newStringProperty();

sp.Name =


sp.Value =


n1.Properties =




I want to create custom entity via custom workflow.I set all of input that I need,and register this plugin but it dosen't work

please guide me

my code is:





CrmWorkflowActivity("GenerateGauranty", "Customs")]


publicpartialclassGenerateGauranty: SequenceActivity





publicstaticDependencyProperty PrefixProperty = DependencyProperty.Register("Prefix", typeof(string), typeof(GenerateGauranty));




publicstring Prefix






return (string)base.GetValue(PrefixProperty);






base.SetValue(PrefixProperty, value);




//type:Look Up


publicstaticDependencyProperty InvoicesProperty = DependencyProperty.Register("Invoices", typeof(Lookup), typeof(GenerateGauranty));






publicLookup Invoices






return (Lookup)base.GetValue(InvoicesProperty);






base.SetValue(InvoicesProperty, value);





publicstaticDependencyProperty ReplaceDateProperty = DependencyProperty.Register("ReplaceDate", typeof(CrmDateTime), typeof(GenerateGauranty));




publicCrmDateTime ReplaceDate






return (CrmDateTime)base.GetValue(ReplaceDateProperty);






base.SetValue(ReplaceDateProperty, value);





publicstaticDependencyProperty StartProperty = DependencyProperty.Register("Start", typeof(CrmNumber), typeof(GenerateGauranty));




publicCrmNumber Start






return (CrmNumber)base.GetValue(StartProperty);






base.SetValue(StartProperty, value);






publicstaticDependencyProperty QuantityProperty = DependencyProperty.Register("Quantity", typeof(CrmNumber), typeof(GenerateGauranty));




publicCrmNumber Quantity






return (CrmNumber)base.GetValue(QuantityProperty);






base.SetValue(QuantityProperty, value);




protectedoverrideActivityExecutionStatus Execute(ActivityExecutionContext executionContext)






IContextService contextService = (IContextService)executionContext.GetService(typeof(IContextService));


IWorkflowContext workflowContext = contextService.Context;


ICrmService crmService = workflowContext.CreateCrmService(true);





if (Prefix != null && Start != null &&  ReplaceDate != null  && Quantity != null)



int S = Start.Value;


for (int i = 0; i < Quantity.Value; i++)



DynamicEntity Delivery = new Microsoft.Crm.Sdk.DynamicEntity();

Delivery.Name =


Delivery.Properties =



StringProperty SerialNumber = newStringProperty();

SerialNumber.Name =


SerialNumber.Value =

string.Concat(Prefix, S.ToString());



LookupProperty Invoice = newLookupProperty();

Product.Name =


Product.Value =

newLookup("invoice", Invoices.Value);



CrmDateTimeProperty ReplaceDates = newCrmDateTimeProperty();

RepairDates.Name =


RepairDates.Value = ReplaceDate;



S += 1;






We are trying to create a Case (Incident) Entity Instance to the Case Entity. We are using the CRMService web service to call a Create method. However this call fails. We have tried this for other entities like Accounts, Contacts and works fine except for the Case Entity. We realize the Case Entity consists of several other related entities. Also we understand in MS CRM 4.0, MS has some restrictions for unknown queries.

Has anyone successfully tried to either Create/Update/Delete the Case Entity?

Any help would be appreciated.







How to Programatically create records for Particular custom entity record in CRM.

For Example I have patient case custom entity, I want to create Audit entity records for

particular patient case (guid).

Any help appriciate...







how to create report and can get guid from entity and display a report by that guid.

Thank You
- kamal -

I am trying to create a new entitiy for a client in CRM 4.0.  When I click on save, I receive and error message staying "Invalid Argument."  CRM was installed on SBS 2003 and was a fresh installation.  Any idea what the problem may be?

Thanks!  Bill Kreuder

I have to create saved search for MS CRM 3.0 'Contact' entity programatically. The code will then be called from MS CRM workflow. Please let me know is there any way we can create saved search programatically? I tried to google for it but couldnt get anything concrete. Please tell me if anybody has done similar task. Thanks in advance!

hello ,

In Crm 4 - Workflow

I want to Create Email that In his body I will set Link to related Entity

like this


how can i set the id of the Entity

When I pass my entity person through wcf to the DAL layer and peform the following code:



Then the state of the person entity is still added ( or modified ). Doesn't the  SaveChanges() resets the entities state?




<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure