[TIPS] Fileds Operation Differences between Form Fields and BPF Fields

 When a form displays a business process flow control in the header, additional controls gets added for each attribute that is been displayed in that BPF. 

These controls hold unique names like: header_process_<attribute name>

So using this control we can write script around these fields.


   * Pay more attention to SET REQUIRED LEVEL, the API is different.





Sample JS Code:

function onLoadOperations (executionContext)
{
    var formContext = executionContext.getFormContext();        

    //Trigered when stage changed
    formContext.data.process.addOnStageChange(hideHousingIncomeFieldInStage);
    hideHousingIncomeFieldInStage (executionContext);
}

function hideHousingIncomeFieldInStage (executionContext)
{
    var formContext = executionContext.getFormContext();        
    var curBPF = formContext.data.process.getActiveProcess();

    //Return when BPF not equals "Private - Case Business Process".
    if ((curBPF != null) && (curBPF.getName() != "BPF TEST FOR STUDENT AID APPLICATION"))
    {
        return;
    }

    //Get active stage name
    var activeStage = formContext.data.process.getActiveStage();
    var stagename = (activeStage != null) ? activeStage.getName() : "";

    if (stagename == "Qualify")
    {  
        //Get Housing Assistance Field Value
        var assistanceAttribute = formContext.getAttribute("hs_housingassistance");
        var housingAssistance = (assistanceAttribute != null) ? assistanceAttribute.getValue() : "";

        if (housingAssistance == true)
        {
            formContext.getControl("header_process_hs_householdincome").setVisible(true);
            formContext.getControl("header_process_hs_householdincome").getAttribute().setRequiredLevel("required");
        }
        else
        {
            formContext.getControl("header_process_hs_householdincome").setVisible(false);
            formContext.getControl("header_process_hs_householdincome").getAttribute().setRequiredLevel("none");
        }
    }

}
============

Please remember to add below protection before the operations in spreadsheet.

var formContext = executionContext.getFormContext();

var attribute = formContext.getAttribute(".....");

//OR var attribute = formContext.getControl(".....");


if (attribute != null 
    && attribute != undefined 
    && attribute != "undefined" 
    && attribute != "null" 
    && attribute != "")
{
    proceed with below operations in spreadsheet.
}

No comments:

Post a Comment