Monday, May 6, 2019

Get Subtab Field Value when Deleting a Record


User have a custom field of type List/Record in record A which points to related record B.
He/She would like to perform some action in Record B (e.g. edit a field, delete record) using a script when Record A is deleted.

If the field in Record A is displayed in main section the value can be pulled using nlapiGetFieldValue.
When the field is in some subtab nlapiGetOldRecord must be used as shown in example below.

function userEventAfterSubmit(type){

    if(type == 'delete')    {
        var recordAId = nlapiGetRecordId();
        var recordA = nlapiGetOldRecord('recordATypeId',recordId);
        var fieldListRecord = recordA.getFieldValue('fieldWhichPointsToRecordB');

        var recordB = nlapiGetOldRecord('recordBTypeId',fieldListRecord);
        recordB.setFieldValue('someFieldInRecordB','record A has been deleted');
        var id = nlapiSubmitRecord(obj);

No comments:

Post a Comment