Hi Mclare,
Please try this way
1. You create 1 js libary and create the follow function:
function executeUnboundFunction (functionName, parameters, successCallback, errorCallback, callerId) {
/// <summary>Invoke an unbound function</summary>
/// <param name="functionName" type="String">The name of the unbound function you want to invoke</param>
/// <param name="parameters" type="Array">An array of strings representing the parameters to pass to the unbound function</param>
/// <param name="successCallback" type="Function">The function to call when the function is invoked. The results of the unbound function will be passed to this function.</param>
/// <param name="errorCallback" type="Function">The function to call when there is an error. The error will be passed to this function.</param>
/// <param name="callerId" type="String" optional="true">The systemuserid value of the user to impersonate</param>
var UriPath = "//Your Web API Url" + functionName;
var parameterNames = [];
var parameterAliasValues = [];
var parameterNumber = 1;
if (parameters) {
parameters.forEach(function (param) {
var keyValue = param.split("=");
var name = keyValue[0];
var value = keyValue[1];
parameterNames.push(name + "=" + "@p" + parameterNumber.toString());
parameterAliasValues.push("@p" + parameterNumber.toString() + "=" + value)
parameterNumber++;
});
UriPath = UriPath + "(" + parameterNames.join(",") + ")?" + parameterAliasValues.join("&");
}
else {
UriPath = UriPath + "()"; }
var req = new XMLHttpRequest();
req.open("GET", encodeURI(UriPath), true);
req.setRequestHeader("Accept", "application/json");
if (callerId) {
req.setRequestHeader("MSCRMCallerID", callerId);
}
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState == 4 /* complete */) {
req.onreadystatechange = null;
if (this.status == 200) {
if (successCallback)
successCallback(JSON.parse(this.response, dateReviver));
}
else {
if (errorCallback)
errorCallback(Sdk.WebApiOperation.errorHandler(this));
}
}
};
req.send();
}
1. Add this library to your form or HTML web resource:
and call this function like:
"Your Library".executeUnboundFunction("", //functionName
null, //your parameters
function(){}, //successCallback
function(){},); //errorCallback
}
Please remember that there are different from BoundFunction and Unboundfunction, refer this link for more information msdn.microsoft.com/.../gg309638.aspx
Regards,