I need to validate if some notes exist in Dynamics 365 before saving and assign (route), the problem is that fetch goes async and save goes sync... I know that by now Microsft recommends going async, so what's the viable solution to do? Save can be canceled and called, but how can I cancel and call the button save and route? or something similar to do this async?
I have tried a lot of similar things, but it doesn't work.
Is there some AddChange to Notes(linked to Entity)?
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:
ApplyRoutingRule
action using webapi Read moreDon’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);
}
);