Archive

Archive for April, 2012

Delete record synchronously using OData and JScript in CRM 2011

April 25, 2012 1 comment

Hi,

Below is the script to delete record synchronously

function deleteRecordSync(recordId, odataSetName) {

// Get Server URL

var serverUrl = Xrm.Page.context.getServerUrl();

//The OData end-point

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var deleteRecordReq = new XMLHttpRequest();

var ODataPath = serverUrl + ODATA_ENDPOINT;

deleteRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid'” + recordId + “‘)”, false);

deleteRecordReq.setRequestHeader(“Accept”, “application/json”);

deleteRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

deleteRecordReq.setRequestHeader(“X-HTTP-Method”, “DELETE“);

deleteRecordReq.send(null);

}

How do I call this method :-

  • To delete an “Account”
  • Pass account GUID and OData Set name (i.e.,AccountSet)

Var accountId=”{Account GUID}”;

deleteRecordSync (accountId , “AccountSet”);

🙂

Update record synchronously using OData and JScript in CRM 2011

Hi,

Below is the Jscript function to update record synchronously using OData and Jscript

function updateRecordSync(id, entityObject, odataSetName) {

var jsonEntity = window.JSON.stringify(entityObject);

// Get Server URL

var serverUrl = Xrm.Page.context.getServerUrl();

//The OData end-point

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var updateRecordReq = new XMLHttpRequest();

var ODataPath = serverUrl + ODATA_ENDPOINT;

updateRecordReq.open(‘POST’, ODataPath + “/” + odataSetName + “(guid'” + id + “‘)”, false);

updateRecordReq.setRequestHeader(“Accept”, “application/json”);

updateRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

updateRecordReq.setRequestHeader(“X-HTTP-Method”, “MERGE“);

updateRecordReq.send(jsonEntity);

}

How do I call this method :-

  • Create a new .jscript file (i.e., “account.js”)
  • Copy & Paste above code
  • Add “account.js” as a webresource in CRM
  • Add “Json2.js” & “jquery1.4.1.min.js” helper script files as webresources
  • Get the helper files from CRM 2011 SDk under path “\sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts”
  • To update an “Account”
  • Pass “Account” object and GUID and OData Set name (i.e.,AccountSet)

Var accountId=”{Account GUID}”;

var account = new Object();

account.Name = “Rajeev Pentyala”;

updateRecordSync (accountId ,account, “AccountSet”);

🙂

Create record synchronously using OData and JScript in CRM 2011

April 19, 2012 4 comments

Hi,

Below is the Jscript function to create record synchronously using OData and Jscript

function createRecordSync(entityObject, odataSetName) {

var jsonEntity = window.JSON.stringify(entityObject);

// Get Server URL

var serverUrl = Xrm.Page.context.getServerUrl();

//The OData end-point

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var createRecordReq = new XMLHttpRequest();

var ODataPath = serverUrl + ODATA_ENDPOINT;

createRecordReq.open(‘POST’, ODataPath + “/” + odataSetName, false);

createRecordReq.setRequestHeader(“Accept”, “application/json”);

createRecordReq.setRequestHeader(“Content-Type”, “application/json; charset=utf-8”);

createRecordReq.send(jsonEntity);

var newRecord = JSON.parse(createRecordReq.responseText).d;

return newRecord;

}

How do I call this method :-

  • Create a new .jscript file (i.e., “account.js”)
  • Copy & Paste above code
  • Add “account.js” as a webresource in CRM
  • Add “Json2.js” & “jquery1.4.1.min.js” helper script files as webresources
  • Get the helper files from CRM 2011 SDk under path “\sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts”
  • To create an “Account”
  • Pass “Account” object, OData Set name (i.e.,AccountSet)

var account = new Object();

account.Name = “Rajeev Pentyala”;

var createdAccount = createRecordSync(account, “AccountSet”);

if (createdAccount) {

alert(“New Account Created !!!; Id – “+createdAccount.AccountId);

}

🙂

Pass parameters to the report hosted in IFrame or Web Page

April 10, 2012 1 comment

Hi,

Assume you have to display related ‘contacts’ of an ‘Account’ in the report hosted in an IFrame.

You can prepare a dataset using below query in the report

SELECT * FROM FilteredContact C

WHERE

C.accountid=@CRM_AccountId

To set parameter @CRM_AccountId‘, you can pass parameter in the URL in this format "&p:CRM_AccountId="={Account GUID}"

Sample URL

var url = Xrm.Page.context.getServerUrl() +  “/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=Internal%20Call%20Report.rdl&id=%7bcd80109a-dc7c-e111-a040-00155dc87c64%7d&records=%7b245DB4C3-927C-E111-9FA1-00155DC87C64%7d&recordstype=1+ “&p: CRM_AccountId=” + accountId;

Below is the useful article explained in detail

Link

Hope it helps 🙂

Opening a report using ribbon button in CRM 2011

April 10, 2012 5 comments

Hi,

To open the Report :-

  • We need report GUID and report associated entity record GUID
  • Get report GUID by using ‘Report Name’ using ‘retrieveMultiple’ function
  • Prepare URl and open new window

Below are the functions

function openReport (reportName) {

var oDataSetName = “ReportSet”;

var columns = “ReportId”;

var filter = “Name eq ‘” + reportName + “‘”;

retrieveMultiple(oDataSetName, columns, filter, onSuccess);

currReportName = reportName;

}

var currReportName;

function onSuccess (data, textStatus, XmlHttpRequest) {

var serverUrl = Xrm.Page.context.getServerUrl();

if (data && data.length > 0) {

var serverUrl = Xrm.Page.context.getServerUrl();

var id = Xrm.Page.data.entity.getId();

var etc = Xrm.Page.context.getQueryStringParameters().etc;

var callReportId = id.replace(‘{‘, ”).replace(‘}’, ”);

var reportId = data[0].ReportId.replace(‘{‘, ”).replace(‘}’, ”);

var url = serverUrl + “/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” + currReportName + “.rdl&id=%7b” + reportId + “%7d&records=%7b” + callReportId + “%7d&recordstype=” + etc;

window.open(url, “reportwindow”, “resizable=1,width=950,height=700”);

}

}

function retrieveMultiple(odataSetName, select, filter, successCallback) {

var serverUrl = Xrm.Page.context.getServerUrl();

var ODATA_ENDPOINT = “/XRMServices/2011/OrganizationData.svc”;

var odataUri = serverUrl + ODATA_ENDPOINT + “/” + odataSetName + “?”;

if (select) {

odataUri += “$select=” + select + “&”;

}

if (filter) {

odataUri += “$filter=” + filter;

}

$.ajax({

type: “GET”,

contentType: “application/json; charset=utf-8”,

datatype: “json”,

url: odataUri,

beforeSend: function (XMLHttpRequest) {

XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);

},

success: function (data, textStatus, XmlHttpRequest) {

if (successCallback) {

if (data && data.d && data.d.results) {

successCallback(data.d.results, textStatus, XmlHttpRequest);

}

else if (data && data.d) {

successCallback(data.d, textStatus, XmlHttpRequest);

}

else {

successCallback(data, textStatus, XmlHttpRequest);

}

}

},

error: function (XmlHttpRequest, textStatus, errorThrown) {

if (XmlHttpRequest && XmlHttpRequest.responseText) {

alert(“Error while retrieval ; Error – ” + XmlHttpRequest.responseText);

}

}

});

}

  • Create a new .Jscript  file and copy above functions
  • Replace double quotes & single quote symbols with keyboard symbols
  • Add the .jscript as web resource
  • Add “json” & “jquery” helper scripts as web resources

How Do I call these methods :-

  • Assume you have a report named “My Account Report” associated (i.e., Related Record Types) to “Account” entity
  • Place a ribbon button on account entity form
  • Call openReport(“My Account Report”) function from ribbon button (How to call function from ribbon button)

Hope it helps 🙂

Disabling sub grid using jscript in CRM 2011

April 9, 2012 3 comments

Hi,

We can’t disable sub grid using out of the box “setDisabled” method.

But there is an unsupported way to disable the grid.

Actually sub grid renders as HTML Span, so we can disable the span using below function

function disableSubgrid(subgridName) {

var subGrid = document.getElementById(subgridName + “_span”);

if (subGrid) {

subGrid.disabled = “true”;

}

}

How Do I call this method :-

  • If your subgrid name is “gridContacts”, Pass the name to the function disableSubgrid(“gridContacts”)

Hope it helps 🙂

Intellisense feature in Sql server management studio 2008 R2 stopped working – Fix

Hi,

You might have lost the Intellisense in ‘Sql server management studio 2008 R2’ after you installed Visual studio 2010 Sp1.

This is a known issue and it got fixed after I installed “Service Pack 1” of Sql server from below link

Download

When you click the above link, from the page download & install “SQLManagementStudio_x64_ENU.exe” and restart the machine

SSMS SP1

SSMS SP1

There might be other reasons for this and it explained in-detail in below article

Link

Hope it helps 🙂