How can I fetch applied timesheets on an invoice i...
# suiteanalytics
t
How can I fetch applied timesheets on an invoice in a search ?
n
we could not find any way to access the join through search or reports. I just looked in Records Browser which shows the name of the time sublist. I looked at Analytics and it doesn't seem to support the join either.
quite a few years ago, we did a customisation for this by adding a custom link field on the time record showing the invoice. we populated that field after an invoice was created. that solved the problem for the customer.
the value you want is in that Time sublist on the Invoice object
here is how we solved it as an after submit User Event on Invoice save.
function afterSubmitUpdateTimeTracking(type)
{
//get the current invoice record
currentRecordId = nlapiGetRecordId();
// nlapiLogExecution ( 'DEBUG', 'current record id', currentRecordId );
var currentRec= nlapiLoadRecord('invoice',currentRecordId);
// Get the number of line Time Tracking items submitted
lines = currentRec.getLineItemCount('time');
//parse the list of time records
for ( var i=1; i<=lines; i++ )
{
//get the ID of the Time Tracking
var timeRecId = currentRec.getLineItemValue('time', 'doc', i);
nlapiLogExecution ( 'DEBUG', 'time rec id', timeRecId );
var timeSelected = currentRec.getLineItemValue('time', 'apply', i);
nlapiLogExecution ( 'DEBUG', 'time selected id', timeSelected );
//if it's selected on the invoice, update its custom field
if (timeSelected == 'T')
nlapiSubmitField('timebill', timeRecId, 'custcol_related_invoice', currentRecordId );
else
{
//ensure that updates on invoices when Time Tracking records are unapplied
var timeRecord = nlapiLoadRecord('timebill', timeRecId);
var invoiceNoSet = timeRecord.getFieldValue('custcol_related_invoice');
if (invoiceNoSet != null)
nlapiSubmitField('timebill', timeRecId, 'custcol_related_invoice', null );
}
nlapiLogExecution('DEBUG', "title Record Updated", "Invoice=" + currentRecordId );
}
//log.debug({
//"title": "Record Updated",
//"details": "Invoice=" + currentRecordId
//});
}
t
Thanks for that, If there are 100s of timesheets this will fail or will degrade the performance.