Sunday, May 5, 2019

How to automatically update a custom field on Time Record when an Invoice is created for the Billable Time?

Prerequisites: One World Account with Intercompany Time and Expenses feature enabled.

Time Transactions are created through Transactions > Employees > Track Time for billable time to a customer or project. When the time is Invoiced a custom field holding the Invoice Number should be automatically populated on the Time Tacking record.

To achieve this result:

  1. Create a Transaction Column Field on the Time Tracking Record with Type = List/Record of Transaction, Applied To = Time, Display Type = Disabled
  2. Create a User Event Script deployed on Invoice with After Submit Function that stamps the Custom Column Field value with the created Invoice Number. The function will retrieve the current Invoice Number and for each of the selected Time Tracking records in the sublist will update the Custom Column Field holding the Invoice Number.
    Script sample:
     function afterSumbitUpdateTimeTracking(type){    //get the current invoice record        currentRecordId = nlapiGetRecordId();    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);        var timeSelected = currentRec.getLineItemValue('time', 'apply', i);        //if it's selected on the invoice, update its custom field        if (timeSelected == 'T')                 nlapiSubmitField('timebill', timeRecId, 'custcol_invoice', currentRecordId );        else            {            //ensure that updates on invoices when Time Tracking records are unapplied            var timeRecord = nlapiLoadRecord('timebill', timeRecId);            var invoiceNoSet = timeRecord.getFieldValue('custcol_invoice');            if (invoiceNoSet != null)                nlapiSubmitField('timebill', timeRecId, 'custcol_invoice', null );                        }        }} 	

Detailed steps on creating and deploying scripts in NetSuite can be found in SuiteAnswers Article Running Scripts in NetSuite Overview.

No comments:

Post a Comment