How to load SSRS report in Web resources In CRM Online

If we have a requirement to show the report on any web resource in dynamics CRM online.

We can utilize the URL to load the report in Web resource IFrame.

below is the code for getting the URL for the report.


var reportName = “YourReportNameHere”, parentEntity =  // Incase your report runs on speficic record.

url = serverUrl + “/crmreports/viewer/viewer.aspx?action=run&helpID=” + reportName + “.rdl&id={“;

//We would need to get the guid of the report and record id in case this report run for a specific record passing parameter.
url = url + GetTheGuidForReport(reportName + “.rdl”) + “}” + “&p:recordid=” + parentEntity.getId();
url = encodeURI(url);

//Finally load the URL In IFrame.

$(“#iFrameForReports”).attr(‘src’, url).attr(‘scrolling’, ‘yes’).attr(‘position’, ‘relative’).attr(‘frameBorder’, ‘0’);



//This function can be used for loading the report  Guild by just passing the report name.
function GetTheGuidForReport(reportName) {
var odataSelect = “$select=filename,name,reportid,reportidunique&$filter=filename eq ‘” + reportName + “‘”,
requestResults = retrieveMultipleRecordsSync (“reports”, odataSelect);
if (requestResults !== null) {
if (requestResults.length > 0) {
if (requestResults[0].reportid === null) {
return false;
} else {
return requestResults[0].reportid;



////************below code is only for reference***************//

//you might want to write your own code for retrieving, as below code is more of generic and here only for reference.

retrieveMultipleRecordsSync = function (type, options, errorCallback) {
stringParameterCheck(type, “retrieveMultipleRecordsSync requires the type parameter is a string.”);
if (options !== undefined && options !== null) {
//stringParameterCheck(options, “retrieveMultipleRecordsSync requires the options parameter is a string.”);

var optionsString, req, results;
if (options !== null) {
if (options.charAt(0) !== “?”) {
optionsString = “?” + options;
} else {
optionsString = options;

req = new XMLHttpRequest();“GET”, getWebAPIPath() + type + optionsString, false);
setRequestHeaders(req); // this function sets the headers for the request.

req.onreadystatechange = function () {
/* complete */
if (this.readyState === 4) {
req.onreadystatechange = null;
switch (this.status) {
case 200:
var queryOptions,
returned = JSON.parse(this.responseText, dateReviver);
results = returned.value;
if (errorCallback !== undefined && errorCallback !== null) {
///errorCallback(errorHandler(this));  // handle the error in your own code.

return results;

//to set the headers of the request.

setRequestHeaders = function (req, includeFormattedValues, customHeaders) {
req.setRequestHeader(“Accept”, “application/json”);
req.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);
req.setRequestHeader(“OData-MaxVersion”, “4.0”);
req.setRequestHeader(“OData-Version”, “4.0”);
if (!(includeFormattedValues !== undefined && includeFormattedValues !== null && includeFormattedValues === false)) {
req.setRequestHeader(“Prefer”, “odata.include-annotations=\”OData.Community.Display.V1.FormattedValue\””);

if (!(customHeaders && customHeaders.constructor === [].constructor)) {
customHeaders = [];
customHeaders.forEach(function (h) {
switch (h.key) {
case “Accept”:
case “Content-Type”:
case “OData-MaxVersion”:
case “OData-Version”:
case “Prefer”:
req.setRequestHeader(h.key, h.value);


removePreSearch does not work


Sometime back I faced the same issue, and I resolved that using the function expression.



* Note: Functions need to be defined using ‘Function expression’ instead of ‘Function declaration’ in order to remove Pre search from a custom control,


var Filterfunction = function () {

var filter = ‘Your fetch XML for filters on Entity’;        Xrm.Page.getControl(“YourFieldName”).addCustomFilter(filter, “EntityLogicalName”);    },

//for removing the existing filters


//for adding the existing filters



Find the Account Where no contacts available

Till now 8.2 version of CRM we can not put an advance query like not null in relationship. see below screen shot.




Now in CRM online we can put child relationship not null filters. see below screen shot.



This new feature at least resolve some advance query problem where we used to feel backward from sql queries.


CRM On Save “Server is Busy” Error

Some time we need to write the code that on save we want to stop the default save event and trigger our own because we want to do some action as we click of the save button but if any plugin error comes we want to revert back that changes or we want to perform some other action.

For example: On click of start button I wan’t to disable some fields but if I get any plugin error and I click okay on that error my fields should again get activated. This is not achievable through the save button click as the default save button doesn’t have a call back function defined from product team. So we need to use the one provide as Save().Then() function.

Call the function onSave on save of button click and pass the execution context.


Code which can be copied.

var isSaveClicked = false; var isSaveClicked = false; var FormTypes = { ‘Create’: 1, ‘Update’: 2 };     function onSave (context) {               if (formType === FormTypes.Create && !isSaveClicked) {            isSaveClicked = true;            context.getEventArgs().preventDefault();            MisXrmUtilities.Common.DisableField(“ABC_FieldField1”);            MisXrmUtilities.Common.DisableField(“ABC_FieldField2”);

////we need to use the timeout function so that service doesn’t get busy

setTimeout(function () {       () {                }, function (error) {                    isSaveClicked = false;                    MisXrmUtilities.Common.EnableField(“ABC_FieldField1”);                    MisXrmUtilities.Common.EnableField(“ABC_FieldField2”);                });            }, 1000);        }    };

Plugin throw customized error, unsaved changes are on form.

I have got one issue when I change some hidden fields on the CRM form and then I was executing the save code for CRM, on save there was one plugin running that throws some handled error message. Now I only get the “OK” and “Download Log” button.

Once i click OK button i still see some unsaved changes

For that if we don’t want to show the unsaved changes on the form below things we can do.

  1. Either find what are all the fields we have changes and set their initial values once you click the okay button (Note: we don’t have any click event given for this ‘OK’) button.
  2. Or some how set the form dirty = false on close of that pop up. (That is also not possible to achieve as we don’t have click/change event)

Solution for this situation would be as below :

  1. we can use save.then() function like below: (success) {
//This is success call back , do whatever you want to do. after save is done.
}, function (error) {

////Please note this getInitialValue only work for optionset and bool fields.;
if (error && error.message) {
//This is the section where we get the error.message in the string format, we can show this in the formnotification.
} else {
// show default message if the error.message is empty or undefined.

‘Go to definition’ failed, either because the caret is already at the definition or because an explicit definition could not be found

In Visual studio if you get this below error. there are below solution we can do.


first check you code doesn’t have any error.

  1. Solution: If its a microsoft product then restart the program or computer system may help.
  2. open console and run below command.

navigate to the directory which visual studio version you are using.

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE>devenv.exe / resetuserdata

How to get the current datetime in CRM client side using Javascript.

I got the issue where I needed to get the datetime as per CRM logged in user timezone. I have written one more blog where we can do this at server side by hitting the org service Get date time as per current user time zone , but how to do that at client side??

Either we can hit the CRM services to get the timezone and calculate the time or we have one simple way to do that as below:

What exactly below code does?

This gets the current machine time and then converts the UTC datetime. after that we calculate crm user datetime by adding the current time zone offset minutes of logged in user.

How to get the offset minutes of the login user?


////Please note: This method is available only after “CRM 2015 Update 1” version.

over all code is as below:

var date = new Date();

var utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());

var crmUserDateTime = new Date(utcDate.setMinutes(utcDate.getMinutes() + Xrm.Page.context.getTimeZoneOffsetMinutes()));

We can ever use jQuery date picker and simply pass the date in var date = new Date(“05/25/2017”);

var date = new Date(“05/25/2017”); // here we can pass multiple formated dates. and any date.

var utcDate = new Date(date.getUTCFullYear(), date.getUTCMonth(), date.getUTCDate(), date.getUTCHours(), date.getUTCMinutes(), date.getUTCSeconds(), date.getUTCMilliseconds());

var crmUserDateTime = new Date(utcDate.setMinutes(utcDate.getMinutes() + Xrm.Page.context.getTimeZoneOffsetMinutes()));

Hope this helps 🙂

Happy learning.

Please follow my blog, so that whenever i create any blog you get notifications.