How to get entity values with OData on dynamics crm/365

Try this code below;


function GenerateODataUrl(depth) {

        var url = "";

        if(depth != undefined && depth == true){
             url = window.parent.Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc";
        }else{
             url = Xrm.Page.context.getClientUrl() + "/xrmservices/2011/OrganizationData.svc";
        }

	return url;
}

function getAccount(Id) {

	var url = GenerateODataUrl() + "/AccountSet?$filter=AccountId eq guid'" + Id + "'";

	$.ajax({
		type: "GET",
		contentType: "application/json;charset=utf-8",
		datatype: "json",
		url: url,
		async: false,
		cache: false,
		beforeSend: function (XMLHttpRequest) {
			XMLHttpRequest.setRequestHeader("Accept", "application/json");
		},
		success: function (data) {   
			debugger;
		},
		error: function (XMLHttpRequest, textStatus, errorThrown) {
			debugger;
		}
	});
}

Advertisements

#ajax-odata, #dynamics-crm-odata, #javascript-odata-request, #odata

How to pass list object with ajax request on Asp.net Mvc

Sample controller and action

 [HttpPost]
 public ActionResult UpdateEmployeePerformance(List<ObjectivesList> ObjectivesList, EmployeePerformance Performance)
 {
     return Json("Ok", JsonRequestBehavior.AllowGet);
 }

Sample Ajax request

$.ajax({
	url: "/Custom/UpdateEmployeePerformanceReview",
	type: "POST",
	data: JSON.stringify({ ObjectivesList: updateObjectivesList, EmployeePerformance  : Performance}),
	dataType: "json",
	async: false,
	contentType: "application/json; charset=utf-8",
	beforeSend: function (XMLHttpRequest) {
		XMLHttpRequest.setRequestHeader("Accept", "application/json");
	},
	success: function (data) {
		debugger
	},
	error: function (XMLHttpRequest, textStatus, errorThrown) {
		debugger;
	}
});

#ajax-list-parameters-request, #ajax-request, #asp-net-mvc, #jquery

How to add lookup filter on custom javascripts

This function bind to form onload “OnLoad”, after calling the “preFilterLookup” function. This method access to form control and add to “addPreSearch” events. In events calling the custom fetchxml functions.

 


function OnLoad() {
preFilterLookup();
}

function preFilterLookup() {
Xrm.Page.getControl("formcontrolelementid").addPreSearch(function () {
addLookupFilter();
});
}

function addLookupFilter() {
fetchXml = "<filter type='and'>"
fetchXml += "<condition attribute='logicalname' operator='eq' value='value' ></condition>";
fetchXml += "</filter>";
Xrm.Page.getControl("formcontrolelementid").addCustomFilter(fetchXml);
}

#custom-js, #lookup, #lookup-filter, #web-resource

Redirect to url after specific time with javascript

Try this


function RedirectUrl(url, interval) {

if (url!= null && url!= '') {

if (interval != undefined && interval != '') {
window.setTimeout(function () {
window.location.href = url;
}, interval);
} else {
window.location.href = url;
}

}

}

#interval, #javascript-url-redirect, #jquery, #settimeout, #url-redirect

How to include javascript file in html dynamically

Try this.


$.ajax({
url: 'library.js',
dataType: 'script',
async: false, //if you change this true, you may receive the error
success: function () {

}
});

#ajax, #dynamic-javascript, #dynamics-library