Skip to main content

Highlight/Visualize Form BPF Required Fields -JS

This was a nifty function I used to highlight required fields for the current BPF stage as a business recommended so the user did not need to expand the BPF but instead the fields would be highlighted with the blue asterisks

HighlightStageRequiredFields = function (executionContext) {
    var formContext = executionContext.getFormContext();
    var activeStage = formContext.data.process.getActiveStage();
    var steps = activeStage.getSteps();
    steps.forEach(function (step) {
        var attribute = formContext.getAttribute(step.getAttribute());
        if (step.isRequired() && (attribute.getValue() === null ||  attribute.getValue() === false)  ) {
            if (attribute.getRequiredLevel() !== "required") {
                attribute.setRequiredLevel("recommended");
            }
        }
    });
};

Register this on load and on process change to highlight the fields as the BPF moves stages. Pair this with a field or custom PCF control to move stages and you never have to expand the BPF.

Watch out for the ands when copying in line 7.