Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Uncaught ReferenceError: Xrm is not defined

Posted on by Microsoft Employee

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

  • Suggested answer
    Fameeda Yaseen Profile Picture
    Fameeda Yaseen 411 on at
    RE: Uncaught ReferenceError: Xrm is not defined

    you can use :

    window.parent.Xrm.Utility.alertDialog in place of Xrm.Utility.alertDialog.

  • Verified answer
    Gopalan Bhuvanesh Profile Picture
    Gopalan Bhuvanesh 11,397 on at
    RE: Uncaught ReferenceError: Xrm is not defined

    Hi

    You cannot use Xrm.Page and Xrm.Utility JS library functions (SDK) in an external application.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans