Hello,
I am trying to Create, Update, Read and Delete entity record of my custom entity in Dynamics 365 using Web API using JavaScript code. But the requirement is I have a HTML web resource having some buttons and html elements in it which are rendering on the entity form of my custom entity. I have my JavaScript code of creating entity record using Web API in another web resource which I am calling in my HTML web resource. My code is as follows:
HTML CODE
<html lang="en" xmlns="">www.w3.org/.../xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript" src="../WebResources/abc_CreateSubjectJS"></script>
</head>
<body>
<input id="subjectname" type="text" /><br /><br/>
<input id="createSubject" type="submit" value="Add New Subject" onclick="createSubjectFunction()" />
</body>
</html>
JAVA SCRIPT CODE
// JavaScript source code
function createSubjectFunction() {
var subject = document.getElementById("subjectname").value;
debugger;
var subjectObj = null;
//var onlineWebApi = parent.Xrm.onlineWebApi;
try {
subjectObj = new Object();
subjectObj.name = "PHY";
Xrm.WebApi.createRecord("abc_subject", subjectObj).then(function (result) {
//get the guid of created record
var recordId = result.id;
//below code is used to open the created record
var windowOptions = {
openInNewWindow: true
};
//check if XRM.Utility is not null
if (Xrm.Utility != null) {
//open the entity record
Xrm.Utility.openEntityForm("abc_subject", recordId, null, windowOptions);
}
},
function (error) {
Xrm.Utility.alertDialog(error.message);
});
} catch (e) {
Xrm.Utility.alertDialog(e.message);
}
}
Here when I debug the function "Xrm.WebApi.createRecord" is not executing. Please help me to solve this issue. Is any wrong in the syntax or is any error. Please let me know.
Thanks
AR