Archive for the ‘Microsoft Dynamic CRM’ Category

Submit A Read-only or Disabled Form Field – Microsoft Dynamic CRM

Monday, May 17th, 2010

Disabling or setting a form field to read-only will cause CRM to ignore any changes to that field on save. For any reason, a form field maybe disabled or set to read-only to prevent the user change the data manually. In some cases, we may need to set the value via form Javascript.

In this case, CRM Form will not save/submit when you make any changes to these disabled fields via form script. Put the following line of script on your form onload event for every disabled/read-only field, to force CRM to submit any changes made to the field.

crmForm.all.NEW_CUSTOMFIELDNAME.ForceSubmit = true;

CRM 4.0 Create customeraddress 0x80040216 An unexpected error occurred

Thursday, March 4th, 2010

When I tried to add more address into an account in CRM, I keep getting this error with error message that doesn’t really help you nail down the problem. If you face the same error or you want to know how to create customeraddress using CRM 4.0 SDK DynamicEntity, please read through. The following simple code highlight how to add address into an account (You can also do on contact by changing the entity name “account” to “contact”. Please note that the values (i.e. street1, street2, city, …) is already set.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var newAddress = new DynamicEntity
  {
     Name = NameOfEntity,
     Properties = new PropertyCollection()
  };
 
var prop = newAddress.Properties;
string addressName = street1 + " " + street2 + " " + city;
prop.Add(new StringProperty("name", addressName));
 
prop.Add(new StringProperty("line1", street1));
prop.Add(new StringProperty("line2", street2));
prop.Add(new StringProperty("city", city));
// .... add other details as necessary ....
prop.Add(new StringProperty("fax", fax));
prop.Add(new StringProperty("primarycontactname", contactName));
 
// .... this is the important property that you should add ...                       
prop.Add(new EntityNameReferenceProperty(AttrObjectType, new EntityNameReference("account")));
prop.Add(new LookupProperty(AttrParent, new Lookup("account", parentId)));
 
var targetCreate = new TargetCreateDynamic {Entity = newAddress};
var request = new CreateRequest {Target = targetCreate};
var response = (CreateResponse)CrmServiceUtil.GetCrmService().Execute(request);
return response.id;

Rule of thumb, do not forget to set the ParentId attribute, as well as ObjectTypeCodeId. That should do the trick. The above code uses .NET 3.0.