Updated SoapLogger tool to generate JavaScript in CRM 2011.


Hi,

There is a SOAPLogger tool that ships with CRM 2011 SDK which can be used to capture HTTP request and response.

http://msdn.microsoft.com/en-us/library/gg594434.aspx

Using that tool we can write our code in C# and and it captures the corresponding SOAP Request and Response for it in a file named Output.txt. I have updated the code so that it formats the SoapRequest in JavaScript which than can be used as web resource in our solution. (It works with Office 365 as well).

The C# code for creating a contact record

And the corresponding output.txt file

Dowload it here :-  SoapLogger   (rename .doc to .zip)

Hope it helps.

Get the total members count of a Dynamic Marketing List in CRM 2011.


Hi,

For a Static Marketing List, we can get the total member count from the attribute “Members Count”.

However this attribute doesn’t’ work for Dynamic Marketing List as this value can only be derived at run time, when the query associated with the list is executed.

One way we can get the total count for the list is by following the below steps.

  • We can get the fetch xml query associated with the Dynamic Marketing List.
  • Remove the attribute and order tag from it.
  • Modify it  to include aggregate function.

Sample Code in C#

 private void btnGetMembersDynamicML_Click(object sender, EventArgs e)
 {
 IOrganizationService orgService = GetOrganizationService();

ColumnSet cols= new ColumnSet(new string[] { "query" });

// GUID of the Dynamic Marketing List
 var entity = orgService.Retrieve("list", new Guid("03C4E473-F7DA-E111-B988-00155D886334"), cols);
 var dynamicQuery = entity.Attributes["query"].ToString();

var countQuery = ModifyFetchXML(dynamicQuery);

var memberCountResult = orgService.RetrieveMultiple(new FetchExpression(countQuery));

DataCollection<Entity> dataCollection = memberCountResult.Entities;

int totalMembers = default(int);
 if(dataCollection != null && dataCollection.Count > 0)
 {
 foreach(Entity entityVal in dataCollection)
 {
 AliasedValue value = (entityVal.Attributes["member_count"] as AliasedValue);
 totalMembers = (int)value.Value;
 }
 }

MessageBox.Show("Total Members : " + totalMembers.ToString());

}

private static string ModifyFetchXML(string dynamicQuery)
 {
 var doc = new XmlDocument();
 doc.LoadXml(dynamicQuery);

var entitynode = doc.GetElementsByTagName("entity")[0];

int childCount = entitynode.ChildNodes.Count;

// Remove all the attribute and order tag
 for (int i = 0; i <= childCount; i++)
 {
 var attributenode = entitynode.SelectSingleNode("//attribute");
 if (attributenode != null) entitynode.RemoveChild(attributenode);
 else
 {
 var ordernode = entitynode.SelectSingleNode("//order");
 if (ordernode != null) entitynode.RemoveChild(ordernode);
 }
 }

// add a new attribute tag
 // <attribute name="fullname" alias="member_count" aggregate="count" />
 XmlElement xmlNodeCustomSettings = doc.CreateElement("attribute");

xmlNodeCustomSettings.SetAttribute("name", "contactid");
 xmlNodeCustomSettings.SetAttribute("alias", "member_count");
 xmlNodeCustomSettings.SetAttribute("aggregate", "count");

entitynode.AppendChild(xmlNodeCustomSettings);

// Add aggregate= true attribute
 // <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" aggregate="true">
 var root = doc.DocumentElement;
 if (root != null) root.SetAttribute("aggregate", "true");

return doc.InnerXml;
 }

public IOrganizationService GetOrganizationService()
 {
 Uri organizationUri = new Uri("http://servername/orgname/XRMServices/2011/Organization.svc");
 Uri homeRealmUri = null;
 ClientCredentials credentials = new ClientCredentials();
 credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
 OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
 IOrganizationService _service = (IOrganizationService)orgProxy;
 return _service;
 }

Hope it helps.

Check out the new section “Form Scripting Quick Reference” in new Microsoft Dynamics CRM SDK Version 5.0.12


Hi,

A new version of CRM 2011 SDK has been recently released

http://www.microsoft.com/en-us/download/details.aspx?id=24004#overview

It includes a section “Form Scripting Quick Reference” that has simple explanations and examples of various Xrm.Page methods in a single page.

Have a look at it here.

http://msdn.microsoft.com/en-us/library/jj602964

Bye.

Sample Code to Retrieve all the members of a Static Marketing List in CRM 2011


Hi,

Below is the code that we could use to retrieve the GUIDs of all the members associated to a STATIC marketing list.

 private void GetAllMembers_Click(object sender, EventArgs e)
 {
 ArrayList memberGuids = new ArrayList();
 IOrganizationService orgService = GetOrganizationService();

PagingInfo pageInfo = new PagingInfo();
 pageInfo.Count = 5000;
 pageInfo.PageNumber = 1;

QueryByAttribute query = new QueryByAttribute("listmember");
 // pass the guid of the Static marketing list
 query.AddAttributeValue("listid", new Guid("2CA7881F-3EDA-E111-B988-00155D886334"));
 query.ColumnSet = new ColumnSet(true);
 EntityCollection entityCollection = orgService.RetrieveMultiple(query);

foreach (Entity entity in entityCollection.Entities)
 {
 memberGuids.Add(((EntityReference) entity.Attributes["entityid"]).Id);
 }

// if list contains more than 5000 records
 while (entityCollection.MoreRecords)
 {
 query.PageInfo.PageNumber += 1;
 query.PageInfo.PagingCookie = entityCollection.PagingCookie;
 entityCollection = orgService.RetrieveMultiple(query);

foreach (Entity entity in entityCollection.Entities)
 {
 memberGuids.Add(((EntityReference)entity.Attributes["entityid"]).Id);
 }
 }

}

public IOrganizationService GetOrganizationService()
 {
 Uri organizationUri = new Uri("http://servername/orgname/XRMServices/2011/Organization.svc");
 Uri homeRealmUri = null;
 ClientCredentials credentials = new ClientCredentials();
 credentials.Windows.ClientCredential = System.Net.CredentialCache.DefaultNetworkCredentials;
 OrganizationServiceProxy orgProxy = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);
 IOrganizationService _service = (IOrganizationService)orgProxy;
 return _service;
 }

Hope it helps.


Thanks Hosk for your appreciation.

Hosk's avatarHosk's Dynamic Blog

Microsoft Dynamics world recently had a survey to find out the best CRM blogs, Richard Knudson discusses the top 5 on his blog this week, which you can read about here.  Although Richard is talking about it because he is featured at number 4.  He certainly deserves to be in the top 5, his blog is consistently excellent, especially considering he is a one man band, where as other blogs featured have a few contributors.

Since I have been using Netvibes I can subscribe to lots of CRM blogs but it is these 5 which produce some of the best articles.  Not only do they produce the best blog entries but the volume of blog entries is incredible from these blogs

Here’s an executive summary, starting with the listing of the top five:

  1. The official Microsoft Dynamics Team Blog
  2. The Customer Effective Blog
  3. A CRM Riff by Jim Glass
  4. Richard Knudson’s Dynamics CRM Trick Bag (this…

View original post 19 more words


Danny Varghese's avatarDanny Varghese's Blog

There’s a new property called “NoLock” added to the QueryExpression class for Microsoft Dynamics CRM 2011.  I found this researching a locking issue on the database we were having for a client.    According to the Microsoft CRM 2011 SDK:

“The benefit of setting NoLock to true is that it allows you to keep the system from issuing locks against the entities in your queries; this increases concurrency and performance because the database engine does not have to maintain the shared locks involved. The downside is that, because no locks are issued against the records being read, some “dirty” or uncommitted data could potentially be read. A “dirty” read is one in which the data being read is involved in a transaction from another connection. If that transaction rolls back its work, the data read from the query using NoLock will have read uncommitted data. This type of read makes…

View original post 35 more words