Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How to solve "HTTP Error 500 - Internal Server Error"

Posted on by 932

Need: - I have a button at Account Home page named Preview on which when i hit that button and then html webresource would be open.

As suggested previous post when i am implement the code and then hit that button it displays an error.

Code and Error is given Below.

Please suggest.

Error_2300_.png

function run(selectedItems)

{

var selectedItem = selectedItems[0];

console.log(selectedItems);

var recordid =selectedItems[0].Id.replace("{","").replace("}","");

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+recordid+")?$select=accountid,address1_city,name", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);

var accountid = result["accountid"];
var address1_city = result["address1_city"];
var name = result["name"];

var url = Xrm.Page.context.getClientUrl() + "//WebResources/new_asdfg" + "?AccountId=" + accountid + "&Name=" + name + "&Address=" + address1_city ;
// give the proper web resource you can find the url by going to web resource details.

openhtmlwindow(url,"page title");

} else {

Xrm.Utility.alertDialog(this.statusText);

}

}

};

req.send();

}

function openhtmlwindow(url, title) {

var w = screen.width - 75;

var h = screen.height - 200;

var left = (screen.width / 2) - (w / 2);

var top = (screen.height / 2) - (h / 2);

var newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

if (window.focus) {

newWindow.focus();

}
}

*This post is locked for comments

  • RE: How to solve "HTTP Error 500 - Internal Server Error"

    Hi Goutam Das,

    As suggested by you, i applied some changes in js and made another html webresource.

    Please check the code of both files and suggest me for the same.

    JavaScript Code: -

    function run(selectedItems)

    {

    var selectedItem = selectedItems[0];

    console.log(selectedItems);

    var recordid =selectedItems[0].Id.replace("{","").replace("}","");

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts("+recordid+")?$select=accountid,address1_city,name", 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.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
    if (this.readyState === 4) {
    req.onreadystatechange = null;
    if (this.status === 200) {
    var result = JSON.parse(this.response);

    var accountid = result["accountid"];
    var address1_city = result["address1_city"];
    var name = result["name"];


    var customParameters = encodeURIComponent("Account ID=accountid&Address=address1_city&Account Name=name");
    Xrm.Utility.openWebResource("new_asdfg.htm", customParameters);

    } else {

    Xrm.Utility.alertDialog(this.statusText);

    }

    }

    }

    }

    HTML Code: -

    <html><head>
    <title>Show Data Parameters Page</title>
    <style type="text/css">
    body
    {
    font-family: Segoe UI, Tahoma, Arial;
    background-color: #d6e8ff;
    }
    tbody
    {
    background-color: white;
    }
    th
    {
    background-color: black;
    color: White;
    }
    </style>
    <script type="text/javascript">
    document.onreadystatechange = function () {
    if (document.readyState == "complete") {
    getDataParam();
    }
    }

    function getDataParam() {
    //Get the any query string parameters and load them
    //into the vals array

    var vals = new Array();
    if (location.search != "") {
    vals = location.search.substr(1).split("&");
    for (var i in vals) {
    vals[i] = vals[i].replace(/\+/g, " ").split("=");
    }
    //look for the parameter named 'data'
    var found = false;
    for (var i in vals) {
    if (vals[i][0].toLowerCase() == "data") {
    parseDataValue(vals[i][1]);
    found = true;
    break;
    }
    }
    if (!found)
    { noParams(); }
    }
    else {
    noParams();
    }
    }

    function parseDataValue(datavalue) {
    if (datavalue != "") {
    var vals = new Array();

    var message = document.createElement("p");
    setText(message, "These are the data parameters values that were passed to this page:");
    document.body.appendChild(message);

    vals = decodeURIComponent(datavalue).split("&");
    for (var i in vals) {
    vals[i] = vals[i].replace(/\+/g, " ").split("=");
    }

    //Create a table and header using the DOM
    var oTable = document.createElement("table");
    var oTHead = document.createElement("thead");
    var oTHeadTR = document.createElement("tr");
    var oTHeadTRTH1 = document.createElement("th");
    setText(oTHeadTRTH1, "Parameter");
    var oTHeadTRTH2 = document.createElement("th");
    setText(oTHeadTRTH2, "Value");
    oTHeadTR.appendChild(oTHeadTRTH1);
    oTHeadTR.appendChild(oTHeadTRTH2);
    oTHead.appendChild(oTHeadTR);
    oTable.appendChild(oTHead);
    var oTBody = document.createElement("tbody");
    //Loop through vals and create rows for the table
    for (var i in vals) {
    var oTRow = document.createElement("tr");
    var oTRowTD1 = document.createElement("td");
    setText(oTRowTD1, vals[i][0]);
    var oTRowTD2 = document.createElement("td");
    setText(oTRowTD2, vals[i][1]);

    oTRow.appendChild(oTRowTD1);
    oTRow.appendChild(oTRowTD2);
    oTBody.appendChild(oTRow);
    }

    oTable.appendChild(oTBody);
    document.body.appendChild(oTable);
    }
    else {
    noParams();
    }
    }

    function noParams() {
    var message = document.createElement("p");
    setText(message, "No data parameter was passed to this page");


    document.body.appendChild(message);
    }
    //Added for cross browser support.
    function setText(element, text) {
    if (typeof element.innerText != "undefined") {
    element.innerText = text;
    }
    else {
    element.textContent = text;
    }

    }
    </script>
    <meta><meta></head>
    <body style="overflow-wrap: break-word;">

    </body></html>

     

  • RE: How to solve "HTTP Error 500 - Internal Server Error"

    Hy Andrew,

    Thanks for help but we can pass custom parameters only the form implemented webresource not other.

    I want show the selected record's data into an html page.

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: How to solve "HTTP Error 500 - Internal Server Error"

    Hello,

    You experience this issue because D365 disallows custom parameters (even for webresources) like AccountId, Name or Address. The only way either use standard like id or put everything under Data parameter. Check my post about it - butenko.pro/.../howto-htmljs-webresources

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: How to solve "HTTP Error 500 - Internal Server Error"

    Hi Shakti ,

    You need to pass query string inside data parameter check here in below post .

    community.dynamics.com/.../pass-parameters-to-html-web-resource

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