Firstly add a custom button in the form using Js code.
Then you can edit the Js code for the button and send ajax request.
$(document).ready(function(){
AddCloseButton();
$('.btn-geyInf').bind('click',function(){
var req = new XMLHttpRequest();
req.open("GET", (Enter the interface here), 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 results = JSON.parse(this.response);
console.log(results.value);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
})
});
function AddCloseButton(){
var button ="<input type='button' class='btn btn-geyInf' value='Get Contact Inf'/>"
$("#EntityFormControl_862039e46daeed11aad1000d3a314363_EntityFormView").next().append(button);
};