Showing posts with label Business Process Flows in MS CRM. Show all posts
Showing posts with label Business Process Flows in MS CRM. Show all posts

Wednesday, June 8, 2016

Validate Business Process Flow using Javascript

function AddStageHandlers() {
    Xrm.Page.data.process.addOnStageChange(StageChangedHandler);
}

function StageChangedHandler() {
    var activeStage = Xrm.Page.data.process.getActiveStage();
    var stageid = Xrm.Page.getAttribute("stageid").getValue();
    var peocessid = Xrm.Page.getAttribute("processid").getValue();
    var stageName = activeStage.getName();
    if (stageName == "BPF Stage Name") {
        if (Xrm.Page.getAttribute("optionsetattributename").getText() == "Yes") {
            if (Xrm.Page.getAttribute("attributename").getValue() == null) {
                //Previous stage ID
                Xrm.Page.data.process.movePrevious(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
            }
            else {
                //Next stage ID
                Xrm.Page.data.process.moveNext(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
            }
        }

        else {
            //Next stage ID
            Xrm.Page.data.process.moveNext(function () { Xrm.Page.data.process.setActiveStage('stageid'); alert("All fields are Mandatory"); });
        }
    };
}