Set a Custom Form on View Mode Depending on a Value of a Record Field

Scenario:

Users may have a need to show or hide fields in a record depending on a value of a particular field in the same record. For scenarios that there are multiple fields and form elements, user may opt in creating different Custom Entry or Transaction Forms. These custom forms should be consistent regardless of the Type. For Types Create and Edit, users can easily utilize Client Scripts particularly the Page Init Function, however it is not triggered when the record is in View type.

Solution

This sample can be used to manage using a Custom Entry Form based on a value of a certain field.

PREREQUISITE: Knowledge in SuiteScript

In this scenario is a Case Record when the status is Escalated a particular Custom Entry form will be used:

STEP A. Prepare a Custom Entry Field for a flag while will prevent undesired looping

1. Navigate to (Administrator)  Customization> Lists, Records, & Fields> CRM Fields> New
2. Set the following values:

Label = Case_Status_Flag
ID = _case_type_flag
Type = Free-Form-Text
Store Value = checked
Applies To> Case = checked
Display> Subtab = Main
Display> Display Type = Hidden

3. Click on Save

STEP B. Create a User Event Script

1. Navigate to (Administrator)  Customization> Scripting>Scripts> New
2. Click on User Event


function updateStatus_Form_Flag(newStatus, _recentRecord){
var caseRec = record.load({
type: record.Type.SUPPORT_CASE,
id: _recentRecord
})
caseRec.setValue(‘custevent_case_type_flag’,newStatus);
caseRec.save();
return;
}//end updateStatus_Form_Flag

function caseBeforeLoad(scriptContext){
var newRec = scriptContext.newRecord;
var fldStatus = newRec.getText({
fieldId: ‘status’
})
var caseTypeFlag = newRec.getValue({
fieldId:’custevent_case_type_flag’
})
var _recentRecord = newRec.id;
var caseFormID;

if ((scriptContexttype == 'view') && (fldStatus != caseTypeFlag)) {//if1
    switch(fldStatus){
    case 'Escalated': //the following value 143 is the Internal ID of the Custom Entry Form to set
    caseFormID = '143'; break;
    //other case Status here
    }//end switch

    if ((scriptContexttype == 'view' && (fldStatus != caseTypeFlag))) {//if2
    updateStatus_Form_Flag(fldStatus, _recentRecord)
    redirect.toRecord({
        type : newRec.type,
        id : newRec.id,
        parameters: {'cf' : caseFormID}
    });

    }//end if2
}//end if1
}//end caseBeforeLoad

reference link: https://suiteanswers.custhelp.com/app/answers/detail/a_id/33993/loc/en_US

Leave a comment

Your email address will not be published. Required fields are marked *