Calculate GST on sum of detail field if conditions met

Calculation question…

I have a detail table and I need to calculate the GST (10%) on the sum of a particular field’s (amount) values.
However, GST only applies if another field (typecode) is equal to 5,6,7,8 or 12. There are many other typecode’s but most are exempt from GST. If none of the aforementioned typecodes exist in the record then GST will be equal to 0.00

Add a column to your detail table named GST. The script for that column should look something like this:

results.each(function(index) {
	var typeCode, result = "";
	typeCode = record.tables["detail"][index].fields["typecode"];
	if([5,6,7,8,12].indexOf(typeCode)>-1) {
		result += record.tables["detail"][index].fields["ItemToal"]*1.1;
	}
	this.html(result);
});

You will need to adjust the field names and add the proper selectors for the column elements, but this script should help you get going.

Thank you so much for the script, however I don’t wish to add the calculation to the detail table, but rather display the GST in another location on the document. Is that possible?

Sure. Create a DIV on your page and add a script for it, similar to this:

var field, result = 0;

for(let i=0;i<record.tables.detail.length;i++){
	
	typeCode = record.tables.detail[i].fields.typecode;
	if([5,6,7,8,12].indexOf(typeCode)>-1) {
		result += record.tables["detail"][i].fields.itemTotal;
	}
}

results.html(result*0.1);

Thank you, that seems to work

Is it possible to call on the result of this GST calculation script within another script?

That is, calculate the GST with a script and then in another script, if a field is a certain value, append the text “(includes GST of ‘TotalGST’)”

Of course. Store the result in a variable, that variable will be available to the second script. You just have to make sure the script that calculates the value runs before the one that displays it (scripts are executed from top to bottom in the list).

Great, thanks for the update, that did the trick