
I have trouble with where I must add XrmServiceToolkit.js and json2.js if I want to use it on button on view. How do I use XrmServiceToolkit on view in CRM 2015?
*This post is locked for comments
I have the same question (0)This works in CRM 2013 but have not tested in 2015.
So create a web resource file for your button. Within this web resource create the following function
YOURNAMESPACE.LoadWebResource = function (resource) {
var httpRequest = null;
try {
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
httpRequest = new XMLHttpRequest();
}
else { // code for IE6, IE5
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
var serverUrl = Xrm.Page.context.getServerUrl();
if (serverUrl.match(/\/$/)) {
serverUrl = serverUrl.substring(0, serverUrl.length - 1);
}
httpRequest.open("GET", serverUrl + "/webresources/" + resource, false);
httpRequest.send(null);
eval(httpRequest.responseText);
}
catch (e) {
alert("LoadWebResource >> Error loading " + resource + ":\n" + e.description);
}
}
Now create another function in the same web resource like the one displayed below
YOURNAMESPACE.buttonFunction = function (selectedId) {
//Load the web resource
YOURNAMESPACE.LoadWebResource("XrmServiceToolkit.js");
//ADD CODE HERE THAT USES THE XrmServiceToolkit
XrmServiceToolkit.Rest.Retrieve(
redId,
"accountSet",
null, "attributename",
function (result)
{
//HANDLE SUCCESS
},
function (error) {
//HANDLE ERROR
},
false
);
}
Now attach YOURNAMESPACE.buttonFunction to your button.
Hope this makes sense and helps at the same time!!
Mark