The CreatorCon Call for Content is officially open! Get started here.

How to populate choice field on form when form is loading (not using default value)

Vijay7
Tera Contributor

Hello all, 
I want to populate 'case type' field which is OOTB field with default value "none" which has 5 choices and I want to populate the field with 'Statement' (which is one of the choice) when we are try to creating the case when form is loading. I don't want to use default 
Is there any way using script Include and client script ?

 

2 REPLIES 2

Chaitanya ILCR
Mega Patron

Hi @Vijay7 ,

if you don't want to update the default value of the field you can create an onload client script which only runs on new records 

function onLoad() {
    if (g_form.isNewRecord()) {
        g_form.setValue('case_type'/*bakend value of the field*/, 'statements'/*bakend value of the choice*/); //replace with backend values
    }
}

 

Regards,
Chaitanya

Pradeep Thipani
Mega Sage
Mega Sage

Hi @Vijay7 ,

 

Just write a OnLoad Client script for Case type field table.

Sample script:

(function() {
    // Check if the form is being loaded for a new case (optional)
    if (g_form.isNew()) {
        // Set the 'case type' field value to 'Statement' on form load
        g_form.setValue('case_type', 'Statement');        //adiust the backend values of choice accordingly 
    }
})();

 

Thanks,

Pradeep

 

 

"If this response was useful, please select 'Accept as Solution' and mark it as 'Helpful.' This helps me provide better answers and assists the community ".

Regards,
Pradeep