For my #2 above: I am expecting that last sumOfAll...
# suitescript
a
For my #2 above: I am expecting that last sumOfAllocations to be 2530.71 because 2474.72+55.99 = 2530.71 but because I am seeing all those extra decimals, I am assuming what is stored in the variable and ultimately being set on the JE line is not the same as what is being displayed on the logs. Is there any way I can ensure the number I am entering on the JE line doesn't come with any "phantom" decimal values. I've tried many combinations of Math.round, .toFixed and, .split and nothing seems to stop those extra decimals from appearing.
b
might need to share the code on this one, potentially with the values behind them
k
Probably, currency exchange issue
It may overwrite you math
b
normally i would recommend using format.format to get nice rounding, but using to.Fixed should have gotten you close
a
i shouldnt be exchanging currency... its all in usd
so i've used .toFixed(2) and the Math.round (val*100)/100 and both are failing me
have even multiplied the amt by100 then .toFixed(0) to then split it into an array to be sure i was only capturing those two decimals and then converted that back into a number
function createNewAllocationLines(objJE, objAllocations, arrValues){
        
var stLogTitle = 'createNewAllocationLines';
        
log.debug(stLogTitle, '##START##');
        
try {
            
for(var index = 0; index<arrValues.length; index++){
                
var objValues = JSON.parse(arrValues[index]);
                
//credit allocated amounts to their correct key account
                
var lenOfAllocations = Object.keys(objAllocations).length;
                
var normalFactor = objAllocations.NORMAL_FACTOR;
                
var amtToAllocate = 0;
                
var sumOfReAllocations = 0;
                
var lineCounter = 0;
                
for(var key in objAllocations){
                    
if(key != "NORMAL_FACTOR"){
                                   
objJE.selectNewLine({
                            
sublistId: 'line'
                        
});
                        
objJE.setCurrentSublistValue({
                            
sublistId: 'line',
                            
fieldId: 'account',
                            
value: objValues.recognitionAcct
                            
});
                        
amtToAllocate = objValues.amount*objAllocations[key]*normalFactor*100;
                        
// amtToAllocate = round(amtToAllocate,2)*1;
                        
// log.debug(stLogTitle, "amtToAllocate - "+amtToAllocate);
                        
var arrOfAmt = (amtToAllocate.toFixed(0)).split("");
                        
log.debug(stLogTitle, "arrOfAmt - "+arrOfAmt.toString());
                        
var arrOfAmtLen = arrOfAmt.length;
                        
var restructuredAmt = 0;
                        
for(var place =0; place<arrOfAmtLen; place++){
                            
var intPartofAmt = parseInt(arrOfAmt[place]);
                            
// log.debug("intPartofAmt",intPartofAmt);
                            
var pow = arrOfAmtLen-place-1;
                            
// log.debug("POW", pow);
                            
var multiplier = Math.pow(10, pow)
                            
// log.debug("multiplier",multiplier);
                            
var newPart = intPartofAmt*multiplier;
                            
// log.debug("newPart",newPart);
                            
restructuredAmt += newPart;
                            
// log.debug(stLogTitle, "loop - restructuredAmt - "+restructuredAmt);
                        
}
                        
restructuredAmt = restructuredAmt/100;
                        
log.debug(stLogTitle, "amtToAllocate - "+amtToAllocate+" restructuredAmt - "+restructuredAmt);
                        
sumOfReAllocations = sumOfReAllocations +restructuredAmt//amtToAllocate;
                        
log.debug(stLogTitle, "sumOfReAllocations - "+sumOfReAllocations);
                        
objJE.setCurrentSublistValue({
                            
sublistId: 'line',
                            
fieldId: 'credit',
                            
value: restructuredAmt// (objValues.department!=2)?amtToAllocate:(amtToAllocate-.01)
                        
});
                        
objJE.setCurrentSublistValue({
                            
sublistId: 'line',
                            
fieldId: 'entity',
                            
value: objValues.clientInternalId
                        
});
                        
objJE.setCurrentSublistValue({
                            
sublistId: 'line',
                            
fieldId: 'department',
                            
value: objValues.department
                        
});
                        
objJE.setCurrentSublistValue({
                            
sublistId: 'line',
                            
fieldId: 'class',
                            
value: key
                        
});
                        
objJE.commitLine({
                            
sublistId:'line'
                        
});
                        
var justSet = objJE.getSublistValue({sublistId: "line",
                                                
fieldId: "credit", line: lineCounter});
                        
log.debug("Recently Set Line - "+lineCounter, " Amount - "+justSet);
                    
}
                    
lineCounter++;
                
}
                
//debit recognition account, amount, memo (original trans/JE?), client, dept,
                
//general key acct (class), NScontract # (text), element # (text), contract rec (internal id)
                
objJE.selectNewLine({
                        
sublistId: 'line'
                    
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'account',
                    
value: objValues.recognitionAcct
                    
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'debit',
                    
value: objValues.amount
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'memo',
                    
value: "Original Recognition JE #"+objValues.journal
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'entity',
                    
value: objValues.clientInternalId
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'department',
                    
value: objValues.department
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'class',
                    
value: 2
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'custcol_contract_no',
                    
value: objValues.sourceTrans
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'custcol_nxt_contract_record',
                    
value: objValues.sourceInternalId
                
});
                
objJE.setCurrentSublistValue({
                    
sublistId: 'line',
                    
fieldId: 'custcol_element_no',
                    
value: objValues.element
                
});
                
objJE.commitLine({
                    
sublistId:'line'
                
});
                
var lineCounter = objJE.getLineCount({sublistId: "line"})-1;
                
var justSet = objJE.getSublistValue({
                        
sublistId: "line",
                        
fieldId: "debit",
                          
line: lineCounter
                    
});
                
log.debug("Recently Set Line - "+lineCounter, " Amount - "+justSet);
                
log.debug(stLogTitle, "Amount Debited: "+objValues.amount+" - Total Amount Credited: "+sumOfReAllocations );
            
}
            
var committedID = objJE.save();
b
you have some wild attempt at rounding going on
a
yeah, the array thing? that was my shot in the dark attempt after the normal ways didn't work.
b
id like to see the attempt without the rounding thrown in
but otherwise you look like you are using dynamic mode
a
without any rounding? and i am
b
you should be able to check what value is in the credits and debits
a
oh yeah how do i do that i couldnt find the field to see what i was off by in total
also i need to round.. i get an error when i don't saying JE's only accept up to two decimal places
b
use format.format to format your number as a currency string
use that value to set your credits or debits
you can parse it afterwards
a
so format.format first then parseFloat before i set the field? or format.format and then set it?
b
format.format to set your field
then parse it for your sum
it probably wont matter for your sum in the end, since you will be rounding it anyways
a
it doesnt like the amount being set as a currency
"message":"You have entered an Invalid Field Value 1,970.81 for the following field: credit",
b
use setCurrentSublistText
a
still not balanced - "message":"The amounts in a journal entry must balance."
d
Try to parse it again in logs parseFloat(sumOfReAllocations).toFixed(2)
b
you should loop through the lines afterwards to see what values you set
and if they are what you expect them to be
a
that's already there in the screenshot
"recently set line - #"
that's after its been commited
so what i am thinking is that even though im setting what i want to set something odd is happening in the background which im guessing means NS is seeing the same thing my summation is seeing.
which is making the JE unbalanced
b
show the logs for the values you set on each line
a
message has been deleted
message has been deleted
message has been deleted
message has been deleted
they sum up correctly.. from a log perspective
b
not really
your last log says you are off by a penny
a
yeah i just rechecked and saw that myself
oooof... i guess ill try more rounding things tomorrow
b
i personally say get rid of your rounding attempts
and rely on the format module to do your rounding for you
internally, it rounds assuming that any difference smaller than a certain amount can be ignored
its pragmatic and will work in the vast majority of cases
a
ill try that out.. i had no idea the format.format had rounding logic in it
i assume that's just for currency formats? or does it round for floats too?
b
it outputs a string with commas, you can't really do anything interesting with it
the idea is to just do your normal math and let format.format round the final results for you
a
oh got it! thanks a bunch