Typically we will cancel the Save event using preventDefault()
, complete the required steps & reissue the Save like discussed here.
In your scenario, special Save & Route
button is achieving Save as well as Apply Routing Rule action. There’s no save mode for this sequence to use getSaveMode
for intercepting & reissue. Reference
But you can try a custom Save & Route button using Ribbon workbench and invoke a custom Javascript action to do:
- Validate your Notes record check using fetchXML/web api
- Save the record
- Call the
ApplyRoutingRule
action using webapi Read more
Don’t forget that Xrm.WebApi
is always Asynchronous, you have to do chain of calls inside success callback or use XMLHttpRequest
for synchronous mode. Read more
Update: I composed this snippet with the help of CRM REST Builder, try it.
var parameters = {};
var target = {};
target.incidentid = "00000000-0000-0000-0000-000000000000";
target["@odata.type"] = "Microsoft.Dynamics.CRM.incident";
parameters.Target = target;
var applyRoutingRuleRequest = {
Target: parameters.Target,
getMetadata: function() {
return {
boundParameter: null,
parameterTypes: {
"Target": {
"typeName": "mscrm.crmbaseentity",
"structuralProperty": 5
}
},
operationType: 0,
operationName: "ApplyRoutingRule"
};
}
};
Xrm.WebApi.online.execute(applyRoutingRuleRequest).then(
function success(result) {
if (result.ok) {
//Success - No Return Data - Do Something
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);