Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Sdk = window.Sdk || {};
- (function () {
- // Code to run in the form OnSave event
- this.formOnSave = function (executionContext) {
- debugger;
- var formContext = executionContext.getFormContext();
- let dateToDeactivateObj = formContext.getAttribute("new_datetodeactivate");
- let customCreationDateObj = formContext.getAttribute("new_customcreationdate");
- if (dateToDeactivateObj.getValue() != null && customCreationDateObj.getValue() != null &&
- (dateToDeactivateObj.getIsDirty() || customCreationDateObj.getIsDirty())) {
- const diffTime = customCreationDate.getTime() - dateToDeactivate.getTime();
- const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
- if (diffDays < 4){
- Xrm.Navigation.openAlertDialog({ text: "Record can not be saved." });
- executionContext.getEventArgs().preventDefault();
- } else {
- // Set Account entity to Inactive status
- formContext.getAttribute("statecode").setValue(1);
- Xrm.Navigation.openAlertDialog({ text: "Record saved." });
- }
- }
- }
- // Code to run in the VIP Account attribute OnChange event
- this.vipAccountOnChange = function (executionContext) {
- debugger;
- var formContext = executionContext.getFormContext();
- let vipAccountNameObj = formContext.getAttribute("new_vipaccount_name");
- if (formContext.getAttribute("new_vipaccount").getValue() == 1) {
- vipAccountNameObj.setValue(formContext.getAttribute("name").getValue());
- } else {
- vipAccountNameObj.setValue("");
- }
- }
- }).call(Sdk);
Advertisement
Add Comment
Please, Sign In to add comment