Hi All,
I have one button is their name Submit.This submit button hide and show the based on grid status.In grid record is actual approved then submit button will enable and record is pending in grid the submit button will not enable.I am write code for this one but its not working its not return any value.
this is my code
function createExpenseButton()
{
debugger;
var formtype=Xrm.Page.ui.getFormType();
if(formtype!=undefined && formtype!=null && formtype>=2)
{
var id = Xrm.Page.data.entity.getId();
var j = 0;
var l = 0;
var results = null;
if(id != null)
{
var travelPlanId = id.replace(/\{|\}/gi, '');
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.1/appointments?$select=pcl_travelplanactivitystatus,_regardingobjectid_value&$filter=_regardingobjectid_value eq " + travelPlanId + "", false);
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) {
results = JSON.parse(this.response);
alert(results.value.length);
for (l = 0; l < results.value.length; l++) {
if (results.value[l].pcl_travelplanactivitystatus == 1 || results.value[l].pcl_travelplanactivitystatus == 798330002 ||
results.value[l].pcl_travelplanactivitystatus == 798330001) {
j++;
}
}
alert(j);
return results.value.length == j;
}
else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
}
}
function createExpense()
{
if(Xrm.Page.getAttribute("statuscode").getValue() != null && Xrm.Page.getAttribute("statuscode").getValue() != undefined)
{Xrm.Page.getAttribute("statuscode").setValue(798330000);
Xrm.Page.getAttribute("statuscode").setSubmitMode("always");}
}
Regards,
Ravi