I have a system I'm designing where I will be creating records, then passing those new records onto other methods for additional processing. When I create the new record I would like to be able to have my other methods treat it as if it's a record that already existed.
For example:
this.ProcessSalesOrder = function(salesOrder) { this.CheckRecordTypeThrowIfError(salesOrder, REC_IDS.SO); this.AddProcessingRecordTrace(salesOrder); // Check the status of the sales order, if it's fulfilled then // we can Invoice it. if(salesOrder.getFieldValue(SO_FIELDS.STATUS) == TRANS_STATUS_LIST.PEND_BILLING) { // Create the invoice record var invoice = nlapiTransformRecord(REC_IDS.SO, salesOrder.getId(), REC_IDS.INVOICE); // Set the invoice date to the same as the sales order date invoice.setFieldValue(TRANSACTION_FIELDS.DATE, salesOrder.getFieldValue(TRANSACTION_FIELDS.DATE)); this.SubmitRecord(invoice, true, true); // now process the Invoice this.ProcessInvoice(invoice); } } this.ProcessInvoice = function(invoice) { this.CheckRecordTypeThrowIfError(invoice, REC_IDS.INVOICE); this.AddProcessingRecordTrace(invoice); } AutoMgr.prototype.AddProcessingRecordTrace = function(record) { this.AddTrace('Processing ' + record.getRecordType() + ' ' + record.getId()); this.IncrementProcessedRecordCount(); } this.SubmitRecord = function(record, doSourcing, addNote) { // determine if this record is new or if it's being updated var updating = (record.getId() != null); var id = nlapiSubmitRecord(record, doSourcing); if(updating) { this.IncrementUpdatedRecordCount(); } else { this.IncrementCreatedRecordCount(); // set the internal ID record.setFieldValue(COMMON_FIELDS.INTERNAL_ID, id); this.AddTrace('Stored the internal ID returned from nlapiSubmitRecord() into the new record that was submitted'); } return id; } In this example you can see that AddProcessingRecordTrace tries to get the id from the record by calling getId(). Problem is, when you create a new record and submit it the internal id (getId()) is null.I've tried assigning the ID returned from nlapiSubmitRecord to the record, but getId() still returns null. I imagine the created date is null as well.I have two questions:[LIST=1][*]Why doesn't nlapiSubmitRecord() assign the internalID and datecreated to the new record?(after reading a little more abot javascript, it seems that you can't pass a variable by reference, so this explains why setting the values doesn't make sense)[*]Is there another method I can use to stuff the internalID into a newly created record?[/LIST]The only workaround I have at this time is to reload the entire record, but that is so wasteful and stupid. There must be another way?What if nlapiSubmitRecord() returned the record with the id and date created set? We wouldn't be losing any functionality, it would simply mean that scripts that expect the id returned would need to get it with getId() - not that big of a deal IMHOThanks for any suggestions or feedback.-Steve