I had a requirement to calculate the real time running average of 3 numeric data fields as the user entered the data.
I wasn't able to find anything on the forum about this and it took me quite some time to figure out, so I thought I'd share the attached UX that has two different methods of achieving the same result:
1. This method uses a calculated field expression in the average field. The calculated field expression calls a javascript function which then returns the result of the calculation.
2. This method uses an OnChange event in each data field. The OnChange event calls a javascript function to perform a calculation then sets the value of the average field with the {dialog.Object}.setValue(); method.
I started out with the first method but it wouldn't work in my particular application because of some prerequisite data that didn't exist initially. So, I switched to the second method as a way to work around the limitation of the first method.
Both methods work fine in the attached example, but there may be times when one or other will work better. The example calculates average for 3 data values but it would be trivial to make this work with as many fields as needed with minor modification.
There may be other ways of doing this, but I as couldn't find any examples just wanted to share in case anyone has a use for this later.
I wasn't able to find anything on the forum about this and it took me quite some time to figure out, so I thought I'd share the attached UX that has two different methods of achieving the same result:
1. This method uses a calculated field expression in the average field. The calculated field expression calls a javascript function which then returns the result of the calculation.
2. This method uses an OnChange event in each data field. The OnChange event calls a javascript function to perform a calculation then sets the value of the average field with the {dialog.Object}.setValue(); method.
I started out with the first method but it wouldn't work in my particular application because of some prerequisite data that didn't exist initially. So, I switched to the second method as a way to work around the limitation of the first method.
Both methods work fine in the attached example, but there may be times when one or other will work better. The example calculates average for 3 data values but it would be trivial to make this work with as many fields as needed with minor modification.
There may be other ways of doing this, but I as couldn't find any examples just wanted to share in case anyone has a use for this later.