从父列表中访问创建的子记录。
子记录是在父记录的子列表中创建的。要访问子记录,可以使用以下步骤:
以下示例代码演示了如何访问在父列表中创建的子记录:
/**
* Create a new child record and access its field
*/
//Get the current sales order record
var mySalesOrder = nlapiLoadRecord('salesorder', 1234);
//Get the internal ID of the first item on the Sales Order
var itemId = mySalesOrder.getLineItemValue('item', 'item', 1);
//Create a new Inventory Adjustment record
var adjustment = nlapiCreateRecord('inventoryadjustment');
//Set the subsidiary and location to match the sales order
adjustment.setFieldValue('subsidiary', mySalesOrder.getFieldValue('subsidiary'));
adjustment.setFieldValue('location', mySalesOrder.getFieldValue('location'));
//Add a new line item for the item on the sales order
adjustment.selectNewLineItem('inventory');
adjustment.setCurrentLineItemValue('inventory', 'item', itemId);
adjustment.setCurrentLineItemValue('inventory', 'adjustqtyby', -1);
adjustment.setCurrentLineItemValue('inventory', 'reason', 'Sales Order');
adjustment.commitLineItem('inventory');
//Save the new adjustment record
var adjustmentId = nlapiSubmitRecord(adjustment);
//Load the newly created child record
var adjustmentRecord = nlapiLoadRecord('inventoryadjustment', adjustmentId);
//Access a field on the child record
var quantity = adjustmentRecord.getLineItemValue('inventory', 'adjustqtyby', 1);
//Log the quantity value
nlapiLogExecution('DEBUG', 'Quantity', quantity);