Reply To: Sum multiple vLookup Total columns

Forums vLooup for SharePoint Sum multiple vLookup Total columns Reply To: Sum multiple vLookup Total columns

#10979
avala
Participant

Thanks, Alexander. I cleaned up the code a little bit but I’m still not getting the vLookup event loaders to work. I’m able to get the functions running off a button click just fine. The entirety of my JS code is below along with our DFFS versions. If there’s anything I can test with DFFS let me know. If it’s code on our end I’ll keep researching.


fields = init_fields_v2();

function vLookupIsLoadedCallback(fin){
	if(fin === "vLookup"){
		CalcTotal();
	}
}

function CalcTotal(){
var vLookupTotal = $(".vLookup_total_vLookup:eq(6)").text();
setFieldValue('Subtotal',vLookupTotal);
var Subtotal = getFieldValue('Subtotal');
var Subtotalnew = parseFloat(Subtotal .replace(/[^0-9-.]/g, ''));
var Tax = getFieldValue('Sales_x0020_Tax');
var Prod = ((Subtotalnew*Tax)/100);
var TotalCalc = (Prod + Subtotalnew);
var result = CurrencyFormatted(TotalCalc);
result = CommaFormatted(result);
setFieldValue('Total',"$" +result);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function CommaFormatted(amount)
{
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
Attachments: