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.
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