deleriumbg

Form Script

Jul 2nd, 2019
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Sdk = window.Sdk || {};
  2.  
  3. (function () {
  4.     // Code to run in the form OnSave event
  5.     this.formOnSave = function (executionContext) {
  6.         debugger;
  7.         var formContext = executionContext.getFormContext();
  8.         let dateToDeactivateObj = formContext.getAttribute("new_datetodeactivate");
  9.         let customCreationDateObj = formContext.getAttribute("new_customcreationdate");
  10.        
  11.         if (dateToDeactivateObj.getValue() != null && customCreationDateObj.getValue() != null &&
  12.             (dateToDeactivateObj.getIsDirty() || customCreationDateObj.getIsDirty())) {
  13.             const diffTime = customCreationDate.getTime() - dateToDeactivate.getTime();
  14.             const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
  15.            
  16.             if (diffDays < 4){
  17.                 Xrm.Navigation.openAlertDialog({ text: "Record can not be saved." });
  18.                 executionContext.getEventArgs().preventDefault();
  19.             } else {
  20.                 // Set Account entity to Inactive status
  21.                 formContext.getAttribute("statecode").setValue(1);  
  22.                 Xrm.Navigation.openAlertDialog({ text: "Record saved." });
  23.             }
  24.         }
  25.     }
  26.  
  27.     // Code to run in the VIP Account attribute OnChange event
  28.     this.vipAccountOnChange = function (executionContext) {
  29.         debugger;
  30.         var formContext = executionContext.getFormContext();
  31.         let vipAccountNameObj = formContext.getAttribute("new_vipaccount_name");
  32.         if (formContext.getAttribute("new_vipaccount").getValue() == 1) {
  33.             vipAccountNameObj.setValue(formContext.getAttribute("name").getValue());
  34.         } else {
  35.             vipAccountNameObj.setValue("");
  36.         }
  37.     }
  38. }).call(Sdk);
Advertisement
Add Comment
Please, Sign In to add comment