I'm trying to make two GL entries when ever a work order completion record is saved and I can only see the GL entries through search. I'm not sure how to make it attached to that record so that we can see it by clicking GL impact on that record.
Is there any way to do this? Here is the user event script I'm using with aftersubmit function.
function enterGL()
{
var recordID = nlapiGetRecordId();
var recordOBJ = nlapiLoadRecord('workordercompletion',recordID);
var journalrec = nlapiCreateRecord('journalentry');
var glID = recordOBJ.getFieldValue('custbody_red_wo_gl_test');
nlapiLogExecution('DEBUG', 'TEST', glID);
var date = recordOBJ.getFieldValue('trandate');
//var line_count = recordOBJ.getLineItemCount('item');
var subsidiary = recordOBJ.getFieldValue('subsidiary');
journalrec.setFieldValue('subsidiary',subsidiary);
journalrec.setFieldValue('currency','1');
journalrec.setFieldValue('trandate', date);
if(glID == null || glID == '')
{
journalrec.selectNewLineItem('line');
journalrec.setCurrentLineItemValue('line','account','251');
//recordOBJ.getLineItemValue('item','amount',i)
journalrec.setCurrentLineItemValue('line', 'debit', '150');
journalrec.commitLineItem('line');
journalrec.selectNewLineItem('line');
journalrec.setCurrentLineItemValue('line','account','343');
journalrec.setCurrentLineItemValue('line', 'credit', '150');
journalrec.commitLineItem('line');
nlapiSubmitRecord(journalrec, true, true);
recordOBJ.setFieldValue('custbody_red_wo_gl_test', journalrec.id);
nlapiSubmitRecord(recordOBJ, true, true);
}
}
Instead of doing a JE which will never show in the GL impact of the record, how about exploring the Custom GL Plugin script