Showing posts with label Business Process Flow. Show all posts
Showing posts with label Business Process Flow. Show all posts

May 4, 2023

Workflow to run against BPF entity

Though we do so many Business Process Flows, it is not that common to trigger another workflow when applying the BPF. Well ,it is possible. As we do in other instances, we only have to select the BPF Entity/ Table and you will see below configuration page which is pretty usual.

If look carefully, you will notice quite different trigger events are lined-up. In given example, we have selected Process is Applied and Process Status changes.


One of the cool things you can do is to set active step depending on some conditions (Conditions in the entity record where BPF is defined based on). For example, if the BPF is done on Account entity, we can control which step BPF should jump into based on some fields of Account. 

Caution

Anyway, there is one situation you have to be careful of. In some cases, we write more than one Business Process Flows and create a switching mechanism in JS Script. So record is jumping to correct BPF upon opening of the record.

In this case, if you write a WF against a BPF which is not the default one, pl keep in mind your Workflow which should have triggered for Process is Applied will not trigger immediately. It will trigger only after someone open the record. Obviously, JS will fire only after record is open and then only correct BPF is applied for the first time. Make sense right ?

Oct 4, 2017

Validate Next Stage button of Business Process Flow

In Business Process Flows in Dynamics 365, we can proceed to next stage by clicking Next Stage button, if all the required fields in the current stage is filled. This is a straight forward validation. Anyway, we may need to do bit more tricky validations through JavaScript.

Let’s see the approach for adding a client script for this event. Please check below code snippet. As you may notice Stage Name and Direction are giving us most needed values to identify when we need to execute our logic.

function onLoad()
{
    Xrm.Page.data.process.addOnStageChange(OnStageProgress);
}

function OnStageProgress(executionContext)
{
    var stageName = Xrm.Page.data.process.getActiveStage().getName();
    var direction = executionContext.getEventArgs().getDirection();
    alert(stageName);
    alert(direction); //Values are Next OR Previous
}

Consider this scenario for an example. I need to move to next stage which is Complete stage if either of Description or Company Name is filled. Let’s extend the logic for that;

function OnStageProgress(executionContext) {
    var stageName = Xrm.Page.data.process.getActiveStage().getName();
    var direction = executionContext.getEventArgs().getDirection();

    var description = Xrm.Page.getAttribute('description').getValue();
    var company = Xrm.Page.getAttribute('parentcustomerid').getValue();

    if ((direction == 'Next') && (stageName == 'Complete'))
    {
    if ((description == null) && (company == null))
    {
        Xrm.Page.data.process.movePrevious(function () {
        Xrm.Page.ui.setFormNotification('Either Description OR Company is required', 'ERROR');
        });
    }
    }
}

Here we get the error message as expected.


Anyway, we need to add Xrm.Page.ui.clearFormNotification(); in onSave event so notices will be cleared when filling either of fields.