Standard Currency Field will not populate

Andrew Bettcher
Kilo Sage

I think this should be an easy one for someone who knows.

I am setting up overtime claims. It will use 3 values to calculate an amount in currency. The values are overtime rate, hourly rate and amount of time (hours and minutes).

Not easy to get those values but, I got them. Now, I need to put the result of multiplying those values, back into a standard currency field (i.e. NOT an FX field).

My info message shows what I think is the correct value and my code matches this but the field remains empty. Any idea what I've done wrong:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
	if (isLoading || newValue === '') {
		return;
	}
	
    

	var hours = g_form.getValue('u_hours_and_minutes');
	var parts = hours.split(" ");
	var dayPart = (parts.length > 1) ? Number(parts[0]) : 0;
	var hourPart = Number(parts[parts.length-1].split(":")[0]);
	var minutePart = Number(parts[parts.length-1].split(":")[1]);
	minutePart = minutePart/60;
	var decimalHours = hourPart + minutePart;
	var rate = g_form.getValue('u_overtime_rate');
	var hourly = g_form.getValue('u_hourly_rate').substring(4);
	var currency = g_form.getValue('u_currency');
	var amount = parseFloat(decimalHours) * parseFloat(rate) * parseFloat(hourly);
	
	g_form.setValue('amount' + currency + ';' + amount);
	g_form.addInfoMessage('Decimal Hours: ' + decimalHours);
	g_form.addInfoMessage('Rate: ' + rate);
	g_form.addInfoMessage('Hourly: ' + hourly);
	g_form.addInfoMessage('Amount: ' + currency + ';' + amount);


	}

The output for the last info statement looks like this:
find_real_file.png

1 ACCEPTED SOLUTION

Andrew Bettcher
Kilo Sage

It's me.... Hooray. I always think that there is a problem with our instance when I can't solve stuff like this.

 

Eagle eyed viewers will note that my setValue was wrong. Once I'd got the right field name in there, I was still trying to + that value into the field when, it should be ','.

Field updates and everyone is VERY happy.

View solution in original post

4 REPLIES 4

Andrew Bettcher
Kilo Sage

Hm. Could it be that the result isn't reliably always to 2 decimal places? I used different values and got:

find_real_file.png

No. I used .toFix(2) and it made no difference. My field still won't populate.

Did a "back to basics" check and found that I was using the wrong field name for my setValue. However, I updated this to the correct one and it still doesn't work.

Also, tried read only and not read only versions of the field.

Andrew Bettcher
Kilo Sage

It's me.... Hooray. I always think that there is a problem with our instance when I can't solve stuff like this.

 

Eagle eyed viewers will note that my setValue was wrong. Once I'd got the right field name in there, I was still trying to + that value into the field when, it should be ','.

Field updates and everyone is VERY happy.