Hi all
I am hoping someone might be able to shed some light on a slight issue I am having with a script I am writing. I am new to this so please be patient
I am trying to add up a column of values from a saved transaction search and place the total in a custom field on the customer record. I have currently set this to run on pageInit.
Most of the script is working now - it is finding the correct search, totalling the correct column and writing it to the correct field. The only problem I am having is getting the script to filter the search results by customer number. (NB I do have the customer number in my search results)
I have tested it along the way to see what different values are being picked up, and it appears that the number of results the script finds equals the total number of results when not constrained by customer number. Here is the offending script...
function releasedUnbilled(){ var recordId = nlapiGetRecordId(); var custId = nlapiLookupField('customer', recordId, 'entityid'); var filters = new Array(); filters[0] = new nlobjSearchFilter('entity', null, 'is', custId); var searchresults = nlapiSearchRecord('salesorder', 2095, filters, null); var balanceTotal = 0; var rlength = searchresults.length; alert ("SEARCH RESULTS =" + rlength); if (searchresults !== null) { for ( var i = 0; searchresults !== null && i < searchresults.length; i++ ) { var searchresult = searchresults[i]; var balance = parseFloat(searchresult.getValue('custbodycustbody_sys_bal_incvat')); balanceTotal = balanceTotal + balance; } } // Set the calculated value nlapiSetFieldValue('custentity_released_unbilled_total', balanceTotal); }If anyone can point me in the right direction I would be most grateful.Peter