Access MS CRM 2011 with IP address ,can get Odata Java Script Query Results

Access MS CRM 2011 with IP address ,can get Odata Java Script Query Results:

 

Some times we may access the CRM with IP address as below.AccessCrmWithIp

 

At this point of time CRM Javascript  Xrm.Page.context.getServerUrl() cant get the Server Url. To over come this use the following Java Script code to get the Server Url.

var serverUrl = document.location.protocol + “//” + document.location.host + “/” + Xrm.Page.context.getOrgUniqueName(); 

This will work fine for the both IP and CRM Serverl Urls.

Please have a glance the below example.

Below i am commenting var serverUrl = Xrm.Page.context.getServerUrl();

function OdataRetrieveMultipleUsingJquery(ODataFilterQuery) {
//var serverUrl = Xrm.Page.context.getServerUrl();

var serverUrl = document.location.protocol + “//” + document.location.host + “/” + Xrm.Page.context.getOrgUniqueName();
var Odata_OrgName = “/xrmservices/2011/OrganizationData.svc”;
var oDataUri = serverUrl + Odata_OrgName + ODataFilterQuery;
var jSonArray = new Array();

jQuery.ajax({
type: “GET”,
contentType: “application/json; charset=utf-8″,
datatype: “json”,
url: oDataUri,
async: false,
beforeSend: function (XMLHttpRequest) {
//Specifying this header ensures that the results will be returned as JSON.
XMLHttpRequest.setRequestHeader(“Accept”, “application/json”);
},
success: function (data, textStatus, XmlHttpRequest) {
if (data && data.d != null) {
jSonArray.push(data.d);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert(“Invalid Record Selection or No Record found with the Search Item”);
}
});

return jSonArray;
}

 

Hope this helps you.

 

Regards,

Route a QueueItem from one Queue to Another Queue using SOAP Code in MS CRM 2011

Route a QueueItem from one Queue to Another Queue using SOAP Code in MS CRM 2011

Some times we may need to route manually queue item to our personal queue on ribbon button click.

Call the below function on custom ribbon button to assign a queue item to your personal Queue or any other queue by passing the Source Queue guid , Destination queue guid and Queueitem guid.

function AssignEmialToQueueUsingEmailGuid(sourceQueueid ,SystemUserPersonalQueueGuid, QueueItemGuid) {
var header = Xrm.Page.context.getAuthenticationHeader();

var xml = “” +
“<?xml version=\”1.0\” encoding=\”utf-8\”?>” +
“<soap:Envelope xmlns:soap=\”http://schemas.xmlsoap.org/soap/envelope/\” xmlns:xsi=\”http://www.w3.org/2001/XMLSchema-instance\” xmlns:xsd=\”http://www.w3.org/2001/XMLSchema\”>” +
header +
” <soap:Body>” +
” <Execute xmlns=\”http://schemas.microsoft.com/crm/2007/WebServices\”>” +
” <Request xsi:type=\”RouteRequest\”>” +
” <Target xsi:type=\”TargetQueuedEmail\”>” +
” <EntityId>” + QueueItemGuid + “</EntityId>” +
” </Target>” +
” <SourceQueueId>” + sourceQueueid + “</SourceQueueId>” +
” <RouteType>Queue</RouteType>” +
” <EndpointId>” + SystemUserPersonalQueueGuid + “</EndpointId>” +
” </Request>” +
” </Execute>” +
” </soap:Body>” +
“</soap:Envelope>” +
“”;

var xmlHttpRequest = new ActiveXObject(“Msxml2.XMLHTTP”);

xmlHttpRequest.Open(“POST”, “/mscrmservices/2007/CrmService.asmx”, false);
xmlHttpRequest.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/crm/2007/WebServices/Execute&#8221;);
xmlHttpRequest.setRequestHeader(“Content-Type”, “text/xml; charset=utf-8″);
xmlHttpRequest.setRequestHeader(“Content-Length”, xml.length);
xmlHttpRequest.send(xml);

var resultXml = xmlHttpRequest.responseXML;
alert(“A Queue Item is Successfully Routed to Your Queue”);
}

Regards,

Activate/Deactivate CRM Entity Record using JavaScript SOAP Code

Activate/Deactivate CRM Entity Record using JavaScript

function ChangeRecordStatus(RECORD_ID, stateCode, statusCode) {
// create the SetState request
var request = “<s:Envelope xmlns:s=\”http://schemas.xmlsoap.org/soap/envelope/\”>”;
request += “<s:Body>”;
request += “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
request += “<request i:type=\”b:SetStateRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\” xmlns:b=\”http://schemas.microsoft.com/crm/2011/Contracts\”>”;
request += “<a:Parameters xmlns:c=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
request += “<a:KeyValuePairOfstringanyType>”;
request += “<c:key>EntityMoniker</c:key>”;
request += “<c:value i:type=\”a:EntityReference\”>”;
request += “<a:Id>” + RECORD_ID + “</a:Id>”;
request += “<a:LogicalName>phonecall</a:LogicalName>”;
request += “<a:Name i:nil=\”true\” />”;
request += “</c:value>”;
request += “</a:KeyValuePairOfstringanyType>”;
request += “<a:KeyValuePairOfstringanyType>”;
request += “<c:key>State</c:key>”;
request += “<c:value i:type=\”a:OptionSetValue\”>”;
request += “<a:Value>” + stateCode + “</a:Value>”;
request += “</c:value>”;
request += “</a:KeyValuePairOfstringanyType>”;
request += “<a:KeyValuePairOfstringanyType>”;
request += “<c:key>Status</c:key>”;
request += “<c:value i:type=\”a:OptionSetValue\”>”;
request += “<a:Value>” + statusCode + “</a:Value>”;
request += “</c:value>”;
request += “</a:KeyValuePairOfstringanyType>”;
request += “</a:Parameters>”;
request += “<a:RequestId i:nil=\”true\” />”;
request += “<a:RequestName>SetState</a:RequestName>”;
request += “</request>”;
request += “</Execute>”;
request += “</s:Body>”;
request += “</s:Envelope>”;

//send set state request

$.ajax(
{
type: “POST”, contentType: “text/xml;charset=utf-8″, datatype: “xml”, url: Xrm.Page.context.getServerUrl() + “/XRMServices/2011/Organization.svc/web”, data: request,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader(“Accept”, “application/xml, text/xml, */*”);
XMLHttpRequest.setRequestHeader(“SOAPAction”, “http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute&#8221;);
}, success: function (data, textStatus, XmlHttpRequest) { Xrm.Page.ui.close(); }, error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});

}

Call the Above function and pass the Record Guid , Statecode and status code of the Record as parameters as shown below.

ChangeRecordStatus(“new_entity”,1,2);

Regards,

 

Open Existing CRM Record Using Java Script

Open Existing CRM Record Using Script

To Open the exisiting CRM Record , pass the Entity Name and Record guid to the below function , it will open the specified record.

//Open an existing Custom record
function OpenExistingEntityRecord(EntityName, RecordGuid) {
Xrm.Utility.openEntityForm(EntityName, RecordGuid);
}

Call the above funciion is as folows.

OpenExistingEntityRecord(“account”,Guid);

You may call this function any event in the CRM

Regards,

Hide the Navigation Pane items in MS CRM 2011

Hide Activities and Closed Activities in the Navigation Pane in MS CRM 2011 Form On load

function hideActivitiesAndClosedActivitiesInNavItems()
{
Xrm.Page.ui.navigation.items.forEach(function (item, index)
{
var itemLabel = item.getLabel();

if (itemLabel == “Activities” || itemLabel == “Closed Activities”)
{
item.setVisible(false);
}
});

}

You may use the above code to hide all navigation items like marketing , Audit History etc.

Make sure your function must call on Form onLoad event.

 

Regards,

Preventing/Cancelling CRM Form onSave event

Preventing/Cancelling CRM Form onSave event

write the below code end of the result.

event.returnValue = false;

return false;

or this may help you the same

In the ValidateData method make sure you have a parameter defined to receive the Execution Object.

function ValidateData(ExecutionObj){
//Place all your data validation here
//In case data is not valid call the below method
// The getEventArgs() method returns an object with methods to manage the Save event.
// The preventDefault() method cancels the save operation
ExecutionObj.getEventArgs().preventDefault();
}

 

Regards,

Disable MS D CRM Form Ribbon Buttons using Java Script on Form Load

Disable MS D CRM Form Ribbon Buttons using Java Script on Form Load.

For Eg. I am trying to disable SAVE , SAVE & NEW , SAVE & CLOSE buttons on Form Load Event

 

function DisableSaveSaveAndCloseSaveAndNewButtons() {

var TelephoneNumber = Xrm.Page.getAttribute(“telephone”).getValue();

if (TelephoneNumber != “” || TelephoneNumber != null) {
//Disable delete button
var Save = top.document.getElementById(“phonecall|NoRelationship|Form|Mscrm.Form.phonecall.Save-Large”);
var SaveAndClose = top.document.getElementById(“phonecall|NoRelationship|Form|Mscrm.Form.phonecall.SaveAndClose-Large”);
var SaveAndNew = top.document.getElementById(“phonecall|NoRelationship|Form|Mscrm.Form.phonecall.SaveAndNew-Medium”);

Save.disabled = true;
SaveAndClose.disabled = true;
SaveAndNew.disabled = true;
Xrm.Page.ui.refreshRibbon();
}
}

 

Cheers,