Showing posts from February, 2013

how to Filter lookup in CRM 2011 by javascript in Client Side.

You can set any lookup with custom view in client. Here is a simple javascript code build dfor CRM 2011.This code run in onLoad of  Response  Custom entity. relation of the entities EntA 1---N EntB 1---N EntC 1-- N EntD for the sample. Filter rule is; Lookup gets only selected EntAs for the EntD function onLoad() { //filter questions for the current EntC var EntCLookup = Xrm.Page.getAttribute("field of the EntityReference of EntC").getValue(); if (EntCLookup != null) { var EntCId = EntCLookup[0].id; var viewId = "{8F03FB3E-0EFF-4417-B704-80CE1711B8D2}";/static guid can obtain by Visual Studio tool var entityName = "EntA"; var viewDisplayName = "EntA Filtered View by EntC"; var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>" + "<entity name='EntA'>&q

how to serialize an object to XML, and vice versa

Hi, Here is code sample of Serializing and Deserializing.There is also some additional methods to convert Byte Array in the sample. i use serialize and deserialize actions by generic in C# private Byte[] StringToUTF8ByteArray(String pXmlString) { UTF8Encoding encoding = new UTF8Encoding(); //UTF8Encoding is under the System.Text namespace Byte[] byteArray = encoding.GetBytes(pXmlString); return byteArray; } private String UTF8ByteArrayToString(Byte[] characters) { UTF8Encoding encoding = new UTF8Encoding(); String constructedString = encoding.GetString(characters); return (constructedString); } private string Serialize(T request) { //MemoryStream is in System.IO //XMLSerializer is in System.Xml.Serialization using (MemoryStream memoryStream = new MemoryStream()) { XmlSerializer xs = new XmlSerializer(typeof(T)); XmlTextWriter

retrieve columns from LinkedEntities in Microsoft CRM 2011

Hi, You prepare QueryExpression and add some LinkedEntities then you want to retrieve fields from linked part.Just follow the sample;  QueryExpression query = new QueryExpression()                     {                                         ...                                         ...                     };                     FilterExpression filterTicket = new FilterExpression();                     ...                     query.Criteria = filterTicket;                     //all about ticket                     query.LinkEntities.Add(new LinkEntity("contact", "new_new_ticket_contact", "contactid", "contactid", JoinOperator.Inner));                     query.LinkEntities[0].EntityAlias = "contacttoticket"; add alias to reach the fields                     query.LinkEntities[0].Columns.AddColumn("new_ticketid"); add column names to the same level of LinkedEntity to obtain later...                

Complex Query in QueryExpression in Microsoft CRM 2011

Hi, Here is tables and relation,QueryExpression statement afterwards. contact 1--->N new_ticket N --> N new_tour QueryExpression query = new QueryExpression()                     {                         EntityName = "contact",                         ColumnSet = new ColumnSet(new string[] {                                                             "contactid",                                                             "firstname",                                                             "lastname",                                                             "birthdate",                                                             "fullname"                                                             }                                                   )                     }; Query Expression will execute the query against contact. For performance issue; do not retrieve any columns that we do

how to insert resource especially System User into Resource Group in Microsoft CRM 2011 SDK

Hi Again, First,we have to get deep technical information about Constraint definition file; here is the definition in XML format; <Constraints>   <Constraint>     <Expression>       <Body>         resource["Id"] == {ac8e6996-ef65-e211-bc9b-005056820011} ||         resource["Id"] == {4a65de5a-d763-e211-bc9b-005056820011} ||         resource["Id"] == {626E49EC-2011-E211-84B5-005056820011}       </Body>       <Parameters>         <Parameter name="resource"/>       </Parameters>     </Expression>   </Constraint> </Constraints> Body tag refers to any resources in the Resource Group. if you add primary key as guid for the record  to the constraint with 'or' logical word, you will see them in the selected resource group in CRM You can get inspiration from AddMembersToTheConstraint methods as shown bolew,Method takes  constraints string and id of mem

Create Resource Group in Microsoft CRM via SDK

Hi, if you create a resource in crm, use ConstraintBasedGroup class. here is a sample code ;     //get current Resource Group     List resourcegroupS = context.ConstraintBasedGroupSet.Where(rg => rg.Name == " ").ToList();     if (resourcegroupS.Count <= 0) //if exists     {                         //create resource group:                         resourcegroupDriver = new ConstraintBasedGroup                         {                             BusinessUnitId = new EntityReference(BusinessUnit.EntityLogicalName, businessunit.Id),                             Name = "Drivers : " + businessunit.Name,                             Constraints = builder.ToString(),                             GroupTypeCode = new OptionSetValue(ConstraintBasedGroupTypeCode.Static),                         };                         xxx.Id = _serviceProxy.Create(resourcegroupDriver);                     }     } if you need more information about 'context&