I found an error when I click a button that calls the action.
and this my code
function test() { alert("3a"); // get the id of the record and remove the curly bracket part // id will be used in Web API url var actionName = "kre_InactiveSuratPesanan"; var Id = Xrm.Page.data.entity.getId().toString(); var statusReason = Xrm.Page.getAttribute("statuscode").getValue(); var suratid = null; suratid = Id.replace('{', '').replace('}', ''); alert(suratid); alert("4"); var inputParameters = {"SuratPesananId" : suratid,"StatusReason": statusReason }; alert("4,5"); var req = new XMLHttpRequest(); var clientUrl = Xrm.Page.context.getClientUrl(); // specify name of the entity, record id and name of the action in the Wen API Url req.open("POST", clientUrl + "/api/data/v8.1/salesorders(" + suratid + ")/Microsoft.Dynamics.CRM.kre_InactiveSuratPesanan", false); alert("5"); req.setRequestHeader("Accept", "application/json"); 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) { req.onreadystatechange = null; if (this.status == 204) { alert("Resource Port has been requested"); Xrm.Page.data.entity.save(); //alert(projectSurveyNodeId); //alert(serviceIdId); } else { var error = JSON.parse(this.response).error; alert(error.message); //alert(this.status); } } }; req.send(window.JSON.stringify(inputParameters)); }