web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

How to call Web API using JavaScript Web Resource in HTML Web Resource

(0) ShareShare
ReportReport
Posted on by 247

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

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    Compared with the following official document examples, there is no problem with the syntax:

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/xrm-webapi/createrecord#basic-create

    Is `Xrm.WebApi.createRecord` skipped or an error occurs during debugging?

    If skipped, whether to check if the record was created?

    In addition, make sure that the table name is a logical name.

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Frank Gong

  • necsa Profile Picture
    3,455 on at

    Hi,

    Hope following link help you:

    softchief.com/.../

  • vishal bagadia_crm Profile Picture
    490 on at

    Are you getting any error??

    Did you tried to add breakpoint under CreateRecord function just to see if that is getting hit or not?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 83 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

#3
#ManoVerse Profile Picture

#ManoVerse 40

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans