I am getting "TypeError: parent.Xrm is undefined" while trying to create a record on click of submit button on html webresource. I am trying to create using WEBAPI call , also have tried to create using xrmservicetoolkit and also tried using xrm.webapi https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/xrm-webapi.
I was using below code.
<html><head>
<meta>
<meta>
<meta>
<meta>
<meta>
<meta></head>
<body style="word-wrap: break-word;">
<!--<script src="gaayam.crm8.dynamics.com/.../new_xrmservicetoolkit"></script>
<script src="gaayam.crm8.dynamics.com/.../new_Jquerytoolkit"></script>
<script src="gaayam.crm8.dynamics.com/.../new_json2toolkit"></script>-->
<p>FirstName: <textarea cols="20" id="myTextBox" rows="1"></textarea></p>
<p>
LastName: <textarea cols="20" id="myTextBox1" rows="1"></textarea>
</p>
<button onclick="MyFunction()">Click Me</button>
<script>
function MyFunction() {
debugger;
var c = document.getElementById("myTextBox").value;
alert(c);
var entity = {};
entity.name = c;
//var xrm = window.parent.Xrm;
var req = new XMLHttpRequest();
req.open("POST", parent.Xrm.Page.context.getClientUrl() + "/api/data/v8.0/accounts", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 204) {
var uri = this.getResponseHeader("OData-EntityId");
var regExp = /\(([^)]+)\)/;
var matches = regExp.exec(uri);
var newEntityId = matches[1];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(entity));
}
</script>
</body></html>
*This post is locked for comments
I have the same question (0)