Fetch query to get Logged in User

<fetch distinct="false" no-lock="false" mapping="logical">

<entity name="audit">

   <attribute name="createdon" />

   <attribute name="action" />

   <attribute name="userid" />


   <attribute name="objecttypecode" />

   <order attribute="createdon" descending="true" />

<filter type='and'>

   <condition attribute='action' operator='eq' value='64'/>


<link-entity name='systemusser' from='systemuserid' to='objectid' link-type='outer' alias='S'>

   <attribute name="fullname" />





CRM 2015: Encryption Error

Error Detail: Cannot perform ‘activate’ because the encryption key doesn’t match the original encryption key that was used to encrypt the data.

Solution: This is applicable when:

  1. You do not have https enabled on your organization.
  2. You have disabled SSLcheck for encryption using,
    UPDATE [MSCRM_CONFIG].[dbo].[DeploymentProperties]
                    SET [BitColumn]=1
                    WHERE ColumnName=’DisableSSLCheckForEncryption’

Go to Email configuration and see if you have any email server profile. If it is there, delete it and try to activate Encryption with a key.

Hope that helps someone 🙂   !



Sharepoint Folder Creation Using Sharepoint Webservices

I had this requirement to create folders in sharepoint through a crm 2013 plugin. I used webservice approach for this.
However, this worked only for CRM On-premise and Sharepoint On-Premise / Sharepoint Online.

It didn’t work for me when I tried to use it from CRM-Online towards Sharepoint Online.

Reason being, Sharepoint Online authentication has a dependency to include Sharepoint.Client and Sharepoint.Client.Runtime assemblies. and CRM online gave me a hard time referencing third party assemblies (even if I tried to use ILMerge)
Here goes the code for creating folders through Lists.asmx webservice :

For this code to run, you need to add web-reference for lists.asmx.


static string FOLDER_EXISTS = “0x8107090d”;
static string SUCCESS = “0x00000000”;
string newFolderName = “test folder name”;
string rootFolderForSharepoint = “”;
string folder1 = <subfolder 1 to be created inside newFoldername;
string folder2 = <subfolder 2 to be created inside newFoldername;
string folder3 = <subfolder 3 to be created inside newFoldername;
string folder4 = <subfolder 4 to be created inside newFoldername;
string rootFolderName = ;
using (Lists listService = new Lists())
listService.Url = ;
System.Net.CredentialCache _myCache = new System.Net.CredentialCache();

string xmlNewCommand = “1SubFolder” + newFolderName + ” ” +

XmlDocument doc = new XmlDocument();

XmlElement ele = doc.CreateElement(“Batch”);
ele.SetAttribute(“OnError”, “Continue”);
//ele.SetAttribute(“RootFolder”, rootFolderForSharepoint );
ele.InnerXml = xmlNewCommand;
_tracing.Trace(“Before getting error”);
XmlNode node1 = null;
_tracing.Trace(“Before get”);

XmlNode test = listService.GetListCollection();

node1 = listService.UpdateListItems(rootFolderName , ele);
catch (Exception ex)

_tracing.Trace(“Node name” + node1.ToString());

if ((node1 != null) && (node1.FirstChild.FirstChild.InnerText == FOLDER_EXISTS) || (node1.FirstChild.FirstChild.InnerText == SUCCESS))
string folder1 = “1. Presentations”, folder2 = “2. Opportunities”, folder4 = “3. Contracts”, folder5 = “4. Projects”; //
// success
string xmlfolder1Command = “1SubFolder” + folder1 + ” ” +
string xmlfolder2Command = “1SubFolder” + folder2 + ” ” +

string xmlfolder4Command = “1SubFolder” + folder4 + ” ” +
string xmlfolder5Command = “1SubFolder” + folder5 + ” ” +

XmlDocument docSubFolder = new XmlDocument();

XmlElement eleSubFolder1 = doc.CreateElement(“Batch”);
eleSubFolder1.SetAttribute(“RootFolder”, rootFolderForSharepoint + newFolderName);
eleSubFolder1.InnerXml += xmlfolder1Command;
XmlNode nodeSubFolders1 = listService.UpdateListItems(rootFolderName , eleSubFolder1);

XmlElement eleSubFolder2 = doc.CreateElement(“Batch”);
eleSubFolder2.SetAttribute(“RootFolder”, rootFolderForSharepoint + newFolderName);
eleSubFolder2.InnerXml += xmlfolder2Command;
XmlNode nodeSubFolders2 = listService.UpdateListItems(rootFolderName , eleSubFolder2);
if ((nodeSubFolders2 != null) && (nodeSubFolders2.FirstChild.FirstChild.InnerText == FOLDER_EXISTS) || (nodeSubFolders2.FirstChild.FirstChild.InnerText == SUCCESS))


XmlElement eleSubFolder4 = doc.CreateElement(“Batch”);
eleSubFolder4.SetAttribute(“RootFolder”, rootFolderForSharepoint + newFolderName);
eleSubFolder4.InnerXml += xmlfolder4Command;
XmlNode nodeSubFolders4 = listService.UpdateListItems(rootFolderName , eleSubFolder4);

XmlElement eleSubFolder5 = doc.CreateElement(“Batch”);
eleSubFolder5.SetAttribute(“RootFolder”, rootFolderForSharepoint + newFolderName);
eleSubFolder5.InnerXml += xmlfolder5Command;
XmlNode nodeSubFolders5 = listService.UpdateListItems(rootFolderName , eleSubFolder5);

throw new InvalidPluginExecutionException(“Create new folder failed for: ” + newFolderName + “. Error Details: ” + node1.OuterXml);
Hope this helps someone 🙂

Cisco AnyConnect VPN does not work with Windows 8.1

I was setting up VPN anyconnect software on my machine today and after installation it did not work.

Little bit of google online and I found solution online –

Do this regEdit change:


Remove all the garbage characters before in DisplayName key “Cisco AnyConnect…”

Hope this helps someone 🙂 !

Setting Field Masking in Microsoft CRM 2013

Upgrading to CRM 2013 and I found that Field masking I was using in CRM 2011 doesn’t work any more.

Here is a fix I got. (Thanks to guy who posted it on this link)

In crm 2011 input field ID is the name of attribute, while in crm 2013 input field ID is the name of attribute plus “_i” (may be “i” denote an input).

So if we have attribute name “name” then input field ID for this attribute in 2011 is “name” and in 2013 it is “name_i”.

Following is the Source view of input field of an attribute on the form in crm 2011 and crm 2013.

Input field in crm 2011

Input field in crm 2013

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format)

// call this function on form load event
function maskFields()
Mask(“address1_postalcode”, “99999-9999”);
Mask(“telephone1”, “(999) 999-9999”);
Mask(“telephone2”, “(999) 999-9999”);
Mask(“fax”, “(999) 999-9999”);

For crm 2013 you should attach “_i” with field name like.

function Mask(field, format)
But also still not working because in crm 2013 input fields are created on execution time. you should apply masking on click event of input, or just got focus of attribute before apply masking e.g.

//Include jquery and jqueryMask plugin file on form you apply masking.
function Mask(field, format) {
//first check whether attribute exist or not
var oCtrl = Xrm.Page.getControl(field);
if (oCtrl != null) {

$(“#” + field + “_i”).mask(format);

// call this function on form load event
function maskFields()
Mask(“address1_postalcode”, “99999-9999”);
Mask(“telephone1”, “(999) 999-9999”);
Mask(“telephone2”, “(999) 999-9999”);
Mask(“fax”, “(999) 999-9999”);



Hope it helps someone!

CRM 2011/2013: Retrieve Multiple records (5000+) using Paging

Was trying to retrieve all records for an entity (Simple enough) and yet took some time (more than what I expected). So thought of documenting it, so that I do not have to spend time on it for syntax.

******************* Here how it goes ****************************

// Create an object of PagingInfo

//queryforContacts is an object for QueryExpression

PagingInfo queryforContacts.PageInfo = new PagingInfo();

int pageNumber =1;

EntityCollection finalCollection = new EntityCollection();
EntityCollection results = new EntityCollection();


// Set records to be retrieved per page
queryforContacts.PageInfo.Count = 5000;

queryforContacts.PageInfo.PagingCookie = (pageNumber == 1) ? null : results.PagingCookie;

// Increment page number
queryforContacts.PageInfo.PageNumber = pageNumber++;

results = serviceProxy.RetrieveMultiple(queryforContacts);
//Set retrieved records in a new EntityCollection
while (results.MoreRecords);

Hope it helps someone 🙂 ! 

window.open not working with CRM 2011 and CRM 2013

Time to refresh some knowledge:

I had been using window.open for opening a dialog from CRM ribbon button for quite sometime. And strangely enough, I never got a chance to do this from Outlook!

(Maybe the reason was that this dialog was used for devlepors only. And you know, we developrs prefer web client more for our day to day CRM adventures.)

But anyways, did that in Outlook and it prompted for credentials.

I was using Xrm.Page.context.getClientUrl() method.

(Remember Xrm.Page.context.getServerUrl() is deprecated and should be replaced with getclienturl).

Some digging around and I found this from MSDN :


Returns the base URL that was used to access the application.

This method is new in Microsoft Dynamics CRM 2011 Update Rollup 12 and the Microsoft Dynamics CRM December 2012 Service Update.

The values returned will resemble those listed in the following table.

Client Value
Microsoft Dynamics CRM (on-premises) http(s)://server/org
Microsoft Dynamics CRM Online https://org.crm.dynamics.com
Microsoft Dynamics CRM for Outlook with Offline Access when offline http://localhost:2525
Return Value
Type: String

 As my setup is an IFD implementation, getClientURl() on outlook returned me path of my ADFS server where Security Token service is installed.

I searched internet a bit and found that there is a workaround:

if (Xrm.Page.context.isOutlookClient()) {
openStdWin(url, ‘Name of Window’,width, height, additionalproperties);
window.open(url, ‘Name of Window’, ‘status=no, width=’ + width + ‘,height=’ + height + ‘,top=’ + posTop + ‘,left=’ +
posLeft + ‘,scrollbars=no,toolbars=no,menubar=no,location=no, align=center,resizable’);

Hope this helps someone !

CRM 2013 : Missing Post / Activities on Notes on Upgraded 2011 tenant

I was customizing my upgraded 2013 environment (from CRM 2011).

Trying to make form layout structure to match new CRM 2013 look, I decided why not to use much talked about Notes/Action/Post tab on top of page.

1. I moved it to top and published the changes. It showed only notes. Posts and Activities were not visible to my eyes. So sad!

2. Read some blogs, regarding upgraded tenants. Suggestion was to activate post configuration for custom entities.  And if that is missing, update Sitemap to get that entity back in CRM Sitemap. Done with fingers crossed.

3. Opened Post configuration entities and activated post configuration for my entity. Published the entity. Removed Notes and Re-inserted those on the forms. Still no luck and my head is at its full pace thinking of what I am missing.

4. And finally, like a voice from heaven. Something pushed me to make a copy of my Existing Main form. Did that . And published. 

Wow. Finally I can see Notes / Post / Activities.

Deactivated the old form. And using new form now. Still looking for any issue because of these changes.

Hope it helps someone 🙂


Microsoft CRM : SQL query for blank Recipient on Phonecall

Recipient field on Phonecall is a business required field. So there are rare chances that it will be left blank on phonecalls.
But sometimes, rare-ities come into picture and become a monster.
That’s what happened to me and I got few corrupted records (duplicates to existing phonecalls) where the recipient on phonecalls were missing. Activities created in the name of user (isworkflow created as 0, which means user created).
My first guess was that probably these are created by a plugin. But alas, no plugin was registered on phonecall.
I suspect that outlook plugin misfired in this scenario (as user who got these gift package of huge number of activities had some outlook issues same day). What makes me think this is : All those gift items were packaged in less than 2 minutes. 
So, it was sure, that user has not done it himself (Sorry for that PJ ).
Now, coming to main point. I wanted to clear my system with this junk. So first step was to query for such records.
That was another issue, as you cant directly query phonecalls based on recipient when recipient is missing (As CRM does not create a respective record for missing party items in Party Table).
Here’s the query to do that :
Approach 1 :
IF OBJECT_ID(‘tempdb..#tmpTemporary’) IS NOT NULL DROP TABLE #tmpTemporary
CREATE TABLE #tmpTemporary(CountParty int, ActivityIds nvarchar(50), Subject nvarchar (200),Owner nvarchar(100), createOnDate datetime, regardingName nvarchar(100))
Insert into #tmpTemporary
 select count(b.activityid) as ‘CountParty’, a.activityid, subject, owneridname, createdon,regardingobjectidname from FilteredActivityParty a
left join filteredactivitypointer b
on a.activityid = b.activityid
where b.activitytypecodename like ‘%phone%’
group by a.activityid, subject, owneridname, createdon, regardingobjectidname
select * from #tmpTemporary
where CountParty not in ( ‘4’, ‘5’, ‘2’)
and regardingName is not null
select * from #tmpTemporary
where CountParty not in ( ‘4’, ‘5’, ‘3’)
and regardingName is null
order by createOnDate desc
Approach 2 :
Thanks to some learned people in this world, they helped me get a simpler version of this query.
select     *
from       FilteredPhoneCall pc left outer join FilteredActivityParty ap
                      on (pc.activityid = ap.activityid and ap.participationtypemaskname = ‘To Recipient’)
where      ap.activityid is null
As my standard saying goes :
Hope it Helps someone 🙂

Remote App and Desktop Connections – Client on Windows XP

Windows 7 and Windows 8 has this amazing feature to connect to a RDP setting published in the format : https://servername/RDWeb/Feed/webfeed.aspx

If you use this url in windows 7/8 it connects (after to proper authentication) and grabs all the applications published to your user and adds it to start menu of your computer.

However, if you try to connect the same using a xp with sp3. this does not work easily.

To achieve this, do following:

1. Download microsoft update and install it on your system

2. Turn on CredSSp. Refer to this link.

3. Restart your machine

4. Now go to start –> all programs –> accessories –> remote desktop connection.

5. Add servername (from https://servername/RDWeb/Feed/webfeed.aspx and ), credentials and here you go connected to host machine.

Hope this helps !

Feel free to let me know if I missed something.

I want to thank numerous online links which helped me do this setting.