Announcements
Within a standard ASP.NET (WebAPI) project, I created this web page for an external site but I am encountering this: Uncaught ReferenceError: Xrm is not defined
Any help will be appreciated.
<!DOCTYPE html>
<html>
<head>
<script src="Scripts/jquery-3.2.1.js"></script>
<title></title>
<meta charset="utf-8" />
<script>
$(document).ready(function () {
var accountlist = $('accountlist');
$('#Getaccounts').click(function () {
console.log("testing 1234")
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts?$select=accountid,name",
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
XMLHttpRequest.setRequestHeader("OData-Version", "4.0");
XMLHttpRequest.setRequestHeader("Accept", "application/json");
XMLHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
},
async: true,
success: function (data, textStatus, xhr) {
var results = data;
for (var i = 0; i < results.value.length; i++) {
var accountid = results.value[i]["accountid"];
var name = results.value[i]["name"];
accountlist.append('<li>' + name + '</li>');
}
},
error: function (xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
});
});
</script>
</head>
<body>
<input id="Getaccounts" type="button" value="Getaccounts" />
<ul id="accountlist " />
</body>
</html>
*This post is locked for comments
you can use :
window.parent.Xrm.Utility.alertDialog in place of Xrm.Utility.alertDialog.
Hi
You cannot use Xrm.Page and Xrm.Utility JS library functions (SDK) in an external application.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,807 Super User 2024 Season 2
Martin Dráb 229,135 Most Valuable Professional
nmaenpaa 101,156