g_form.setValue() is not Working

anuragsingh1
Tera Contributor

I am trying to run a simple script but it is not working as it is not setting the values in the field.
SCRIPT=>

function onSubmit() {
   //Type appropriate comment here, and begin script below
   var checkIn = g_form.getValue('check_in_date_and_time');
	var checkOut = g_form.getValue('check_out_date_and_time');
	var isGovernmentEmployee = g_form.getValue('government_employee');
	var roomPrice = 0;
	var discount = 0, tax = 0;
	var roomType = g_form.getValue('room_type');
	var isGuestIdTypeGovernmentId = g_form.getValue('guest_id_type') == 'Government Employee Id';
	
	
	
	if(checkOut < checkIn) {
		g_form.addErrorMessage("Please enter correct check out date and time");
		return false;
	}
	
	if(!(isGovernmentEmployee && isGuestIdTypeGovernmentId)) {
		g_form.addErrorMessage("Please enter Government Employee Id");
		return false;
	}
	
	if (roomType == 'Single Room') {
		roomPrice = 2000;
	}
	if(roomType == 'Duplex Room'){
		roomPrice = 3000;
	}
	if(roomType == 'Suite'){
		roomPrice = 5000;
	}
	if(roomType == 'Presidential Suite'){
		roomPrice = 8000;
	}
	discount = (roomPrice * 30) / 100;
	if(isGovernmentEmployee){
		g_form.setValue('discount', discount);
	}
	g_form.setValue('room_charge', roomPrice);
	tax = (roomPrice*18)/100;
	g_form.setValue('tax', tax);
	
	return true;
}

 

All the setValue() functions are not working but we are getting the correct values and other condition is working properly as i print the values of  roomType and roomPrice variables and they are correct

anuragsingh1_0-1688564316754.png

 

----------------------------------------------------------------------

anuragsingh1_1-1688564351391.png

-------------------------------------------------------------------------

anuragsingh1_2-1688564391509.png

--------------------------------------------------------

anuragsingh1_4-1688564418933.png

But it is not working
I want to set totalCharge, discount and tax

1 REPLY 1

Nishchitha K S
Tera Guru

Hello @anuragsingh1 Please check the field type and backend names of the field you are trying to set the value.