简体   繁体   中英

How can I work with save and route button Dynamics 365?

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:

  1. Validate your Notes record check using fetchXML/web api
  2. Save the record
  3. 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);
    }
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM