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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)
Active Discussion

not fetching the records in to html

(0) ShareShare
ReportReport
Posted on by

Hi Everyone,

Greetings for the day!!!

I need a help regarding fetching records to  html using webapi

I have written java-script code and the code is successfully executing but when it comes to html including i'm getting error please help on this.. See the below code and suggest me further where i have struck regarding the output. 

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="cdnjs.cloudflare.com/.../font-awesome.min.css">
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function searchbutton() {
debugger;
var req = new XMLHttpRequest();
req.open("GET", window.parent.Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts?$select=name", false);-->query is not reading the req.open method 
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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
//var accountid = results.value[i]["accountid"];
var name = results.value[i]["name"];
// console.log(name);
$("#tb").append("<tr><td>" + name + "</td></tr>");

}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
</script>


<body bgcolor="blue" onload="searchbutton()" style="word-wrap:break-word" >
<center><h1>Email formate Design</h1></center><br />
From : <input type="text" name="fromaddress" value="" align="left"><br />
To :
<select style="color : #fff " align="left">
<table id="tb" style="width:100%;">
<tbody>
<tr>
<th style="text-align:left">Name</th>

</tr>
</tbody>
</table>


</select>
<button onclick="searchbutton()" type="submit"><i class="fa fa-search"></i></button>
</body>
</head>

</html>

Regards,

Narendra

*This post is locked for comments

  • ChetanKhanapure Profile Picture
    81 User Group Leader on at

    You need to call the webapi get request through the Ajax. Below I have demonstrate the pic of code you can try this.

    function searchbutton() {

    $.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts?$select=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=\"OData.Community.Display.V1.FormattedValue\"");
    },
    async: false,
    success: function (data, textStatus, xhr) {

           //result you will gets the Data from Account
           var result = data;
           //Rest of the Logic goes here Ex.
           $("#HtmlField").val(result["CRMField"]);
          },
          error: function (xhr, textStatus, errorThrown) {
        }
      });
    }

  • Community Member Profile Picture
    on at

    Thank you Chetan for ur valuable Response

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans