Monthly Archives: September 2012

Working with MS CRM 2011 data types

I have seen many question in MS CRM Development where developers asking for MS CRM 2011 data type related question, like how to set lookup field, how to set/retrieve optionset value. so I thought to write code to show how we can set different data type field in MS CRM 2011.

Below is the example to create account using late bound

Entity _Account = new Entity();
_Account.LogicalName = “account”;
//setting text field
_Account.Attributes.Add(“name”, “Myaccount123”);

//setting optionset field
_Account.Attributes.Add(“accountcategorycode”, new OptionSetValue(2));

//setting datetime field
_Account.Attributes.Add(“new_collectiondate”, new DateTime(2012, 3, 25));

//setting currency field
_Account.Attributes.Add(“creditlimit”, new Money(300));

//setting lookup
_Account.Attributes.Add(“parentaccountid”, new EntityReference(“account”, new Guid(“XXX-XXX……..”)));

//setting decimal
_Account.Attributes.Add(“new_executivecommission”, new Decimal(55.5));

//setting boolean
_Account.Attributes.Add(“new_isbilled”, true);


we should get new account created like below

In next post I will show how to retrieve different data types fields using server side code.

Enjoy !!!



Filed under MS CRM 2011

Fetch team members for selected Team

I got one requirement to get all team members based on team, so I thought to share code here so that it can help other crm developers. you can use below code

private EntityCollection GetTeammembers(IOrganizationService _iService,Guid TeamID)
EntityCollection _Teammembers = null;
Guid _UserId = Guid.Empty;
EntityCollection col = new EntityCollection();
QueryExpression _Query = new QueryExpression();
_Query.EntityName = “systemuser”;
_Query.ColumnSet = new ColumnSet(new string[] { “systemuserid”, “firstname” });
LinkEntity _LinkEntity = new LinkEntity();
_LinkEntity.LinkFromAttributeName = “systemuserid”;
_LinkEntity.LinkToAttributeName = “systemuserid”;
_LinkEntity.LinkFromEntityName = “systemuser”;
_LinkEntity.LinkToEntityName = “teammembership”;
_LinkEntity.JoinOperator = JoinOperator.Natural;
_LinkEntity.LinkCriteria = new FilterExpression();
_LinkEntity.LinkCriteria.AddCondition(“teamid”, ConditionOperator.Equal, TeamID);
_Teammembers = _Service.RetrieveMultiple(_Query);
return _Teammembers;

Enjoy !!!

Leave a comment

Filed under MS CRM 2011

InstantiateTemplateRequest using Javascript – MS CRM 2011

If you want to create new email using template or want to place email template contents to email while replying, you need to use”InstantiateTemplateRequest” to initiate email template. It has three below parameters

TemplateId (ID of the email template that you want to use)

ObjectId (associated entity record id, (for example you have used data field from user entity then this will be the system user id)

ObjectType (data field’s associated entity name)

In my example, I have used system user entity’s data fields in my template, so here is the code to Initiate email template using Soap request.

function InstatiateEmailTemplate(TemplateID, FromUser) {
var Soapreq = “<s:Envelope xmlns:s=’’>&#8221; +
“<s:Body><Execute xmlns=’; xmlns:i=’’>&#8221; +
“<request i:type=’b:InstantiateTemplateRequest’ xmlns:a=’; xmlns:b=’’>&#8221; +
“<a:Parameters xmlns:c=’’>&#8221; +
“<a:KeyValuePairOfstringanyType>” +
“<c:key>TemplateId</c:key>” +
“<c:value i:type=’d:guid’ xmlns:d=’’>&#8221; + TemplateID + “</c:value>” +
“</a:KeyValuePairOfstringanyType>” +
“<a:KeyValuePairOfstringanyType>” +
” <c:key>ObjectType</c:key>” +
”          <c:value i:type=’d:string’ xmlns:d=’’>systemuser</c:value>&#8221; +
”       </a:KeyValuePairOfstringanyType>” +
”      <a:KeyValuePairOfstringanyType>” +
”       <c:key>ObjectId</c:key>” +
”      <c:value i:type=’d:guid’ xmlns:d=’’>&#8221; + FromUser + “</c:value>” +
”   </a:KeyValuePairOfstringanyType>” +
“</a:Parameters>” +
“<a:RequestId i:nil=’true’ />” +
“<a:RequestName>InstantiateTemplate</a:RequestName>” +
“</request>” +
“</Execute>” +
“</s:Body>” +

Enjoy !!

Note: if you are copying this code, please make sure to change quotes.


Filed under MS CRM 2011