I am trying to replace a value in a search.create function with a filter. the filter returns one or more objects, and i store them in an array. On accessing the array, i want to replace a certain value with 0, if a certain field 'lastinv' is empty. here is my code below;
// a is lastinv
if (a == null || a == '') {
todate = format.format({
value: todate,
type: format.Type.DATE
});
// creates a custom search on a record with specific filters
var reading = search.create({
type: 'customrecord_ew_meterreading_form',
columns: ['name', 'id', 'custrecord_ew_mr_metername', 'custrecordmeternumber', 'custrecord_ew_mr_site', 'custrecord1', 'custrecord_ew_meterreading_value'],
filters: [{
name: 'custrecord_ew_mr_site',
operator: search.Operator.IS,
values: site
}, {
name: 'custrecord1',
operator: search.Operator.ON,
values: todate
}] // end of filter*/
});
// gets a custom search for the readings of a site on the
// firstdate/lastdate of the month and stores in a array called ar_readings
reading.run().each(function(result) {
ar_reading.push(result);
return true;
});
return ar_reading;
}
And this next part is me trying to replace the value on a certain index;
for (var k = 0; k < firstReading.length; k++) {
ar_mtrdata[k] = new Array();
var l_meternumber = firstReading[k].getValue('custrecordmeternumber');
var mtrdtls = getMeterDetails(l_meternumber);
ar_mtrdata[k][0] = mtrdtls.getValue('itemid'); // Meternumber
if (lastinv == '' || lastinv == undefined || lastinv == null) {
ar_mtrdata[k][2] = 0;
} else {
ar_mtrdata[k][2] = firstReading[k].getValue('custrecord_ew_meterreading_value'); // previous reading
}
/* ... */
}