How to do it...

  1. Navigate to Settings | Solutions | Packt.
  2. Click on Web Resources and click on New, enter packt_/js/concurrency.js as the name, select JScript from Type, and then click on Text Editor.
  3. Copy and insert the following piece of code:
var packtNs = packtNs || {}; 
packtNs.concurrency = packtNs.concurrency || {};
var _recordLoadedVersion;
var _schemaName = "";
var _saving = false;

packtNs.concurrency.init = function (schemaName)
{
_schemaName = schemaName;
var modifiedResult =
packtNs.concurrency.checkLastModified("0");
_recordLoadedVersion = modifiedResult.modifiedVersion;
Xrm.Page.ui.clearFormNotification("concurrency");
Xrm.Page.data.entity.removeOnSave(packtNs.concurrency.checkConcurrency);
Xrm.Page.data.entity.addOnSave(packtNs.concurrency.checkConcurrency);
}

packtNs.concurrency.checkConcurrency = function (executionObj)
{
if(_saving){
return;
}
var saveMode = executionObj.getEventArgs().getSaveMode();
executionObj.getEventArgs().preventDefault();

var modifiedObject = packtNs.concurrency.checkLastModified(_recordLoadedVersion);

if (!modifiedObject.hasChanged) {
packtNs.concurrency.callSecondSave(executionObj, saveMode);
return;
}

if (saveMode === 70) {
Xrm.Page.ui.setFormNotification("Seems like this record has been updated by " + modifiedObject.modifiedBy + ". AutoSave has been aborted.", "WARNING", "concurrency");
}
else if (saveMode === 59 || saveMode === 2 || saveMode === 1) {
Xrm.Utility.confirmDialog("Seems like this record has been updated by " + modifiedObject.modifiedBy + ". Are you sure you still want to save it?",
function () {
packtNs.concurrency.callSecondSave(executionObj,saveMode);
},
null);
}
}

packtNs.concurrency.callSecondSave = function (executionObj, saveType){
//Omitted code. Call the correct save method.
}

packtNs.concurrency.checkLastModified = function (recordLoadedVersion)
{
//Omitted code. Compare the result from JSON @odata.etag with recordedLoadedVersion
}
  1. Back in your Packt solution in Dynamics 365, navigate to Entities | Contact | Forms and double-click on the Main form.
  2. Click on Form Properties and under Form Libraries, click on + Add
  3. Select your JavaScript library created in step 2 from the list (you can use the search functionality to filter the values) and click on Add, then click on OK.
  4. Under Event Handlers, verify that Control is set to Form and Event is set to OnLoad, then click on +Add.
  5. Ensure that packt_/js/concurrency.js is selected in the Library dropdown and then enter packtNs.concurrency.init in the Function field.
  6. Enter contacts in the parameter field.
  7. Click on Save and Close, followed by Publish All Customizations in your solution window.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.131.238