Set value of a reference field on ui page client script

Ulrich Matthew
Tera Contributor

Hi everyone ,

 

im trying to set a fixed value to a field in a workspace form , but no matter what i do it won't change

Screenshot 2024-07-03 at 14.49.07.png

 The field "consumer should change to "Guest" when i click on the following button

Screenshot 2024-07-03 at 14.49.49.png

this button is defined in UI builder and controlled by a client script

 

 

 

**
 *  {params} params
 *  {api} params.api
 *  {any} params.event
 *  {any} params.imports
 *  {ApiHelpers} params.helpers
 */
function handler({
    api,
    event,
    helpers,
    imports
}) {

   


     // Clear Caller or Set as Guest?
            var eventName = event.id;
            var actionMethodElementId;
            var gform = api.data.gform.nowRecordFormBlob.gForm;
            if(eventName == "NOW_SPLIT_BUTTON#ACTION_CLICKED"){
                // top-level button clicked
                //actionMethodElementId = event.context.item.value.resultActions.primaryAction.id;
                if(event.payload.item.id == 'split_button_1'){
                    var consumer = referenceField == 'x_tcoj2_church_ct_caller_name' ? gform.getValue('consumer') : gform.getValue('x_tcoj2_church_ct_requested_for_consumer');
                    api.setState("ccLookupUser", consumer);
                }else if(event.payload.item.id == 'split_button_2'){
                    var internalContactUser = referenceField == 'x_tcoj2_church_ct_caller_name' ? gform.getValue('internal_contact') : gform.getValue('x_tcoj2_church_ct_requested_for_internal_contact');
                    api.setState("ccLookupUser", internalContactUser);
                }

            } else {
                // dropdown button clicked
                actionMethodElementId = event.payload.item.id;
            }
            // if(actionMethodElementId == 'clearCaller'){
            //     var clearFieldsArr = ['x_tcoj2_church_ct_caller_church_account','x_tcoj2_church_ct_caller_unit','x_tcoj2_church_ct_caller_name','x_tcoj2_church_ct_caller_phone','x_tcoj2_church_ct_caller_email','x_tcoj2_church_ct_caller_unit_number','x_tcoj2_church_ct_caller_position','x_tcoj2_church_ct_caller_country','internal_contact','consumer'];
    		//     for(var i=0; i<clearFieldsArr.length; i++){
    		// 	    gform.setValue(clearFieldsArr[i], '');
            //     }
            //}else
             if(actionMethodElementId == 'callerGuest'){
                gform.setValue('consumer','5136503cc611227c0183e96598c4f706'); 			
    	        gform.setValue('internal_contact','5136503cc611227c0183e96598c4f706');
    	        gform.setValue('x_tcoj2_church_ct_caller_country','');
                gform.setValue('short_description','test');
		
                	
            }


   
    
}

 

 

the field is declared this way

 

Screenshot 2024-07-03 at 14.53.04.png

Thanks a lot

 

0 REPLIES 0