Create a Custom Transaction Body Field in Purchase Order record
- Navigate to Customization > Lists, Records, & Fields > Transaction Body Fields > New
- Fill up the required fields such as desired label of the custom field for Expected Delivery Date in Purchase Order record
- Ensure that the type is in Date
- In Applies to field, check Purchase
- Adjust desired Display settings in Display tab
- Save, and take note of the internal ID created for the custom field
A User Event script using afterSubmit function will be triggered when an Inbound Shipment record is created or edited and have its Expected Delivery Date sourced in the Purchase Order record.
function afterSubmit(context) {
var recid = context.newRecord.id;
if (context.type == context.UserEventType.CREATE || context.type == context.UserEventType.EDIT){
var rec = record.load({
type: context.newRecord.type,
id: recid
})
var expecteddeliverydate = rec.getValue(‘expecteddeliverydate’)
var numLines = rec.getLineCount({
sublistId: ‘items’
});
for(var i = 0; i<numLines; i++){
var POnum = rec.getSublistValue({
sublistId: ‘items’,
fieldId: ‘purchaseorder’,
line: i
});
var POrec = record.load({
type: record.Type.PURCHASE_ORDER,
id: POnum
})
POrec.setValue({
fieldId: ‘custbody3‘,
value: expecteddeliverydate,
ignoreFieldChange: true
});
POrec.save();
}
}
}