Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Calling action in custom button

$
0
0

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));
}



Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>