SodaMedia
Soda Media Presenting all A to Z Updates and support for Microsoft Dynamics 365 D365 MSCRM
Sunday, 3 December 2023
Saturday, 1 August 2020
ButtonClick
// JavaScript source code
var Report = window.Report || {};
var users = [];
var emails = [];
Report.OnFinalizeButtonClick = function (primaryControl) {
Xrm.Utility.
var formContext = primaryControl;
if (formContext !== null) {
//// Get CE Plan ID
var planID;
var cePlan = formContext.getAttribute("
if (cePlan !== null) {
planID = cePlan[0].id;
}
//// Get All Notes For CE Plan
Report.FetchAllNotes(
}
};
Report.OnPingForCeNotes = function (primaryControl) {
Xrm.Utility.
var formContext = primaryControl;
if (formContext !== null) {
//// Get CE Plan ID
var planID;
var cePlan = formContext.getAttribute("
if (cePlan !== null) {
planID = cePlan[0].id;
}
//// Get All Notes For CE Plan
Report.FetchAllNotes(
}
};
Report.FormReadOnly = function (formContext) {
if (formContext !== null) {
formContext.data.entity.
var control = formContext.getControl(
if (control) {
control.setDisabled(true);
}
});
formContext.getAttribute("
var id = "Notification";
var message = "record is set to read only mode".toUpperCase();
var level = "INFO";
formContext.ui.
//// formContext.data.entity.save()
}
};
Report.FetchAllNotes = function (formContext, cePlanId, checkCondition, recordId) {
if (formContext !== null) {
var usersWhoSentNotes = [];
var req = new XMLHttpRequest();
req.open("GET", Xrm.Utility.getGlobalContext()
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
// alert(results.value[i]["yash_
// usersWhoSentNotes.push(
usersWhoSentNotes.push(
}
Report.
} else {
Alert(this.statusText);
}
}
};
req.send();
}
};
Report.
if (formContext !== null) {
if (emails.length > 0) {
emails = [];
}
if (users.length > 0) { users = new Array(); }
var ownerCEPlan = formContext.getAttribute("
var req = new XMLHttpRequest();
req.open("GET", Xrm.Utility.getGlobalContext()
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
var yash_
Report.pushUsers(
}
//// Check For Owner Of Record
if (ownerCEPlan !== null) {
var checkForOwner = usersWhoSentNotes.includes(
if (!checkForOwner) {
if (!users.includes(ownerCEPlan[
}
}
if (users.length > 0) {
//// Show Confirmbox for Selection
Xrm.Utility.
var message = '';
users.forEach(x => { message += '\n' + x; });
var usersEmail = '';
if (checkCondition === 0) {
var confirmStrings = { text: " This CE Report hasn't got CE Notes from below users :\n" + message, confirmButtonLabel: "Publish", cancelButtonLabel: "Send Reminder For Notes", title: "Do you want to publish CE Report ?" };
var confirmOptions = { height: 300, width: 550 };
Xrm.Navigation.
if (success.confirmed) {
if (summary !== null) {
}
else {
//// Condition For Ping Button Click
Xrm.Utility.
Report.SendNotification(
}
}
else {
Xrm.Utility.
formContext.getAttribute("
Report.FormReadOnly(
}
} else {
Alert(this.
}
}
};
req.send();
}
};
Report.ShowAlert = function (message) {
var alertStrings = { confirmButtonLabel: "Close", text: message, title: "Need Executive Summary" };
var alertOptions = { height: 200, width: 450 };
Xrm.Navigation.
function success(result) {
// console.log("Alert dialog closed");
},
function (error) {
// console.log(error.message);
}
);
};
Report.GetUserName = function (id, usersWhoSentNotes) {
var req = new XMLHttpRequest();
req.open("GET", Xrm.Utility.getGlobalContext()
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
var systemuser = results.value[i]["fullname"];
var systemuseremail = results.value[i]["
var systemCheck = usersWhoSentNotes.includes(
if (!systemCheck) {
users.push(systemuser);
emails.push(systemuseremail);
}
}
} else {
Alert(this.statusText);
}
}
};
req.send();
};
Report.SendNotification = function (formContext, usersEmail, message, CEPlanID) {
formContext.getAttribute("
emails.forEach(x => { usersEmail += x + ';'; });
formContext.getAttribute("
/// Calling Flow For Sending Email Notification
Report.CallFowForEmail(
setTimeout(function () {
formContext.ui.
},
10000
);
};
Report.Onload = function (executionContext, attributeName, attributeQualificationDetails) {
var formContext = executionContext.
if (formContext !== null) {
Report.ShowHideCEPlanDetails(
var checkIsreadOnly = formContext.getAttribute(
var checkIsReOpened = formContext.getAttribute(
if (checkIsReOpened === 2 && checkIsreadOnly) {
Report.FormReadOnly(
formContext.getAttribute("
var control = formContext.getControl("yash_
if (control) {
control.setDisabled(false);
}
}
else if (checkIsreadOnly) {
Report.FormReadOnly(
}
}
};
Report.LiteCEReport = function (executionContext) {
var formContext = executionContext.
if (formContext !== null) {
formContext.getAttribute("
formContext.getAttribute("
}
};
Report.ShowHideCEPlanDetails = function (formContext) {
if (formContext !== null) {
var checkValue = formContext.getAttribute("
if (checkValue === null) {
formContext.getControl("yash_
// formContext.getControl("yash_
formContext.getControl("
//formContext.getControl("
//formContext.getControl("
}
else {
formContext.getControl("yash_
formContext.getAttribute("
}
}
};
function ExecutiveSummary(
var formContext = executionContext.
if (formContext !== null) {
var checkValue = formContext.getAttribute("
if (checkValue !== null) {
var ID = "CE Notification";
var message = "Ping for Notes or Complete the Executive Summary and hit “Publish Report”".toUpperCase();
var level = "INFO";
formContext.ui.
setTimeout(function () {
formContext.ui.
},
50000
);
}
}
}
function HideButtons(primaryControl) {
var formContext = primaryControl;
if (formContext !== null) {
var checkValue = formContext.getAttribute("
if (checkValue !== null) {
return true;
}
return false;
}
}
function ValidateDate(executionContext) {
var formContext = executionContext.
if (formContext !== null) {
var today = new Date();
var Startdate = formContext.getAttribute('
if (Startdate > today) {
alert("Date and time cannot be future date");
formContext.getAttribute('
}
else {
formContext.getAttribute('
}
}
}
// JavaScript source code
Report.ShowQylifyfield = function (executionContext) {
var formContext = executionContext.
if (formContext !== null) {
/// get Logged in user role Id
var userSettings = Xrm.Utility.getGlobalContext()
// Get Logged In User Security Roles
var loggedInUsersecurityRolesGuidA
var totalSecurityRolesArray = new Array();
//var arreyToCheck = [];
if (
Xrm.WebApi.online.
function success(result) {
if (result.entities.length > 0) {
// Push Role Names and Role Ids to Array
for (var rolesCount = 0; rolesCount < result.entities.length; rolesCount++) {
totalSecurityRolesArray.push({ RoleName: result.entities[rolesCount].
}
// Compare the User Security Roles with Total Security Roles
for (var userSecurityRolesCounter = 0; userSecurityRolesCounter < loggedInUsersecurityRolesGuidA
for (var totalsecurityRolesCounter = 0; totalsecurityRolesCounter < totalSecurityRolesArray.
if (totalSecurityRolesArray[
}
}
}
},
function (error) {
// Show error
Alert(error.message, null);
});
}
}
};
Report.AccountOnchange = function (executionContext) {
var formContext = executionContext.
var accountid = formContext.getAttribute("
if (formContext !== null && accountid !== null) {
var lookupid = accountid[0].id.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Utility.getGlobalContext()
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
var new_accounttype = results.value[i]["new_
formContext.getAttribute("
formContext.data.entity.save()
}
} else {
Alert(this.statusText);
}
}
};
req.send();
}
else {
formContext.getAttribute("
}
};
Report.OnQualifySelect = function (executionContext) {
var formContext = executionContext.
if (formContext !== null) {
var qualify = formContext.getAttribute("
var accountType = formContext.getAttribute("
if (accountType === 100000002 && qualify === 3) {
var message = "You can not qualify prospect type account as \"Half Credit\"";
Report.ShowAlert(message);
formContext.getAttribute("
}
}
};
Report.AccountupOnchange = function (executionContext) {
var formContext = executionContext.
var globalcontext = Xrm.Utility.getGlobalContext()
var Client = globalcontext.getClientUrl();
var accountname = formContext.getAttribute("
if (formContext !== null && accountname !== null) {
var req = new XMLHttpRequest();
req.open("GET", Client + "/api/data/v9.1/accounts?$
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
var name = results.value[i]["name"];
var new_accounttype = results.value[i]["new_
var new_accounttype_formatted = results.value[i]["new_
formContext.getAttribute("
}
} else {
Alert(this.statusText);
}
}
};
req.send();
}
else {
formContext.getAttribute("
}
};
function Alert(message) {
var alertStrings = { confirmButtonLabel: "Ok", text: message };
var alertOptions = { height: 150, width: 400 };
Xrm.Navigation.
function success(result) {
},
function (error) {
}
);
}
// JavaScript source code
function HideQulification(
var formContext = executionContext.
if (formContext !== null) {
var CEReportstattus = formContext.getAttribute("
if (CEReportstattus === true) {
formContext.ui.tabs.get("
}
}
}
Report.OnNotQualifiedStatus = function (executionContext) {
var formContext = executionContext.
if (formContext !== null) {
if (formContext.getAttribute("
var control = formContext.getControl("yash_
if (control) {
control.setDisabled(false);
}
formContext.getAttribute("
formContext.getAttribute("
formContext.getAttribute("
formContext.getAttribute("
}
else if (formContext.getAttribute("
var _control = formContext.getControl("yash_
if (_control) {
_control.setDisabled(true);
}
formContext.getAttribute("
}
}
};
Report.pushUsers = function (recordId, usersWhoSentNotes) {
if (recordId !== null) {
// var usersWhoSentNotes = [];
var req = new XMLHttpRequest();
req.open("GET", Xrm.Utility.getGlobalContext()
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-
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);
for (var i = 0; i < results.value.length; i++) {
var name = results.value[i]["yash_name"];
var email = results.value[i]["yash_email"]
var check = usersWhoSentNotes.includes(
if (!check) {
users.push(name);
emails.push(email);
}
}
} else {
Alert(this.statusText);
}
}
};
req.send();
}
};
అప్ట్= new XMLHttpRequest();
req.setRequestHeader("OData-
req.setRequestHeader("OData-
req.setRequestHeader("Accept", "*/*");
req.setRequestHeader("Content-
req.setRequestHeader("Prefer", "odata.include-annotations=\"*
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
formContext.data.save();
formContext.ui.
} else {
formContext.data.save();
formContext.ui.
}
}
};
req.send(JSON.stringify({
"CePlan": ce_plan_id,
"CeReport": Ce_Report_id
}));
};