Friday 1 January 2016

Change Business Process flow in JavaScript in CRM 2016 by Business Process Flow Name

 


In  the following function I am getting Business Process name from an Option Set and passing to Webapi query by getting Business Process flow Id and then Changing  Business flow  on Opportunity Entity form.


function ChangeBusinessProcessFlow() {
        try {

            var opportunityType = Xrm.Page.getAttribute("po_opportunitytype");
            if (opportunityType != null) {

                var opportunityTypeName = opportunityType.getSelectedOption().text;

                if (opportunityTypeName != null || opportunityTypeName != '') {

                    var odataQuery = "workflows?$select=workflowid,name &$filter=name eq '" + opportunityTypeName + "'";
                    var oDataEndpointUrl = Xrm.Page.context.getClientUrl() + "/api/data/v8.0/" + odataQuery;
                    var service = new XMLHttpRequest();
                    service.open("GET", oDataEndpointUrl, false);
                    service.setRequestHeader("Accept", "application/json");
                    service.setRequestHeader("OData-MaxVersion", "4.0");
                    service.setRequestHeader("OData-Version", "4.0");

                    service.send();

                    if (service.readyState == 4 /* complete */) {
                        if (service.status == 201 || service.status == 200) {
                            var data = JSON.parse(service.response);
                            if (data.value.length > 0) {
                                if (data.value[0].workflowid != null) {

                                    Xrm.Page.data.save().then(function () {

                                        Xrm.Page.data.process.setActiveProcess(data.value[0].workflowid, afterChangeBpf);

}
            }
        } catch (ex) {
            alert("error occured in ChangeBusinessProcessFlowOnOpportunityType() function");
        }
    
}
function afterChangeBpf() {
    
}

  

No comments:

Post a Comment

Numbering Table Parent group and child group ssrs report

 Recently I have faced a scenario to numbering parent group and subgroup in the following formate 10 parentGroupRow1    10.1 childGroupRow1 ...