I have been working on a search.create function where I need to replace a value with a filter. The filter returns one or more objects which are then stored in an array. My goal is to replace a specific value with 0 if the field 'lastinv' is empty. Below is the code snippet for reference:
// checking if 'a' is lastinv
if (a == null || a == '') {
todate = format.format({
value: todate,
type: format.Type.DATE
});
// creating 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*/
});
// running a custom search for the readings of a site on the
// first date/last date of the month and storing them in an array called ar_reading
reading.run().each(function(result) {
ar_reading.push(result);
return true;
});
return ar_reading;
}
Now, I am attempting to update the value at a specific index as shown below:
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
}
/* ... */
}