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 :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 958

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

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

  • Shakti Singh Rajput Profile Picture
    958 on at

    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.

  • Shakti Singh Rajput Profile Picture
    958 on at

    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>

     

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans