Team,
I've a condition on the "Feedback Record Status" column say if "Status=Resolved" it checks if there is any pending tasks in "Active".If there is no "Active" tasks it auto populates the "closed Date" with todays date. And click save&Close.
But the issue here is if any "Active" tasks are open it will show a "Pop-up" message saying "Close all pending tasks" . However we can still make the status as "Resolved" and "Save & Close" the record which should not happen.
Can you please advise/update the attached script and restrict without closing the record if the tasks are in "Active" state.
################################################################
function checkTaskStatus(){
var id = Xrm.Page.data.entity.getId();
var feedbackRecordStatus = Xrm.Page.getAttribute("new_feedbackrecordstatus").getValue();
if (feedbackRecordStatus == 100000003) {
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/tasks?$filter=_regardingobjectid_value eq '" + id + "' and statecode eq 0&$count=true", 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);
var recordCount = results["@odata.count"];
if (recordCount > 0) {
Xrm.Utility.alertDialog("Please Complete All The Tasks.");
}
else {
var today = new Date();
today.setHours(0, 0, 0, 0);
Xrm.Page.getAttribute("new_closeddate").setValue(today);
}
for (var i = 0; i < results.value.length; i++) {
var activityid = results.value[i]["activityid"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
}
function futuredatevalidation() {
var fieldDate = Xrm.Page.getAttribute('new_closeddate').getValue();
if (fieldDate != null) {
fieldDate.setHours(0, 0, 0, 0);
var today = new Date();
today.setHours(0, 0, 0, 0);
if (fieldDate > today) {
Xrm.Page.getAttribute("new_closeddate").setValue(null);
Xrm.Utility.alertDialog("You can't enter future date");
}
}
}
#######################################################
@rampprakash