Hello,
On the Account form, I need a Navigation Link (left) with a dynamic URL with the Lead's email address as part of the URL.
I'm only able to catch the GUID of the account but not other fields.
I have followed this tutorial (www.crmanswers.net/.../dynamic-navigation-links-using.html) and created a HTML Web Resource.
Script seems to fail at the "$.ajax({" part:
<HTML><HEAD>
<SCRIPT type=text/javascript src="ClientGlobalContext.js.aspx" script></SCRIPT>
<SCRIPT type=text/javascript src="code.jquery.com/.../SCRIPT>
<SCRIPT language=javascript>
function GoToDynamicUrl(accountName) {
var dynamicUrl = "www.bing.com/search + accountName;
location.href = dynamicUrl;
}
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
function retrieveRecord(id, odataSetName, successCallback, errorCallback) {
var context = Xrm.Page.context;
var serverUrl = context.getServerUrl();
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (successCallback) { successCallback(data.d); }
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
if (errorCallback) { errorCallback(errorThrown); }
}
});
}
function retrieveSuccess(data) {
// we call the GoToDynamicUrl function with the Account Name
alert(data.Name);
GoToDynamicUrl(data.Name);
}
function retrieveError(error) {
alert("Error: " + error);
}
</SCRIPT>
<META charset=utf-8></HEAD>
<BODY contentEditable=true>
<SCRIPT language=javascript>
// Retrieve the id from the query string
var id = getURLParameter('id');
// Retrieve the record and call the success function
retrieveRecord(id, 'AccountSet', retrieveSuccess, retrieveError);
</SCRIPT>
</BODY></HTML>