Does anyone know why anything below the first log....
# suitescript
l
Does anyone know why anything below the first log.debug does not execute? The purpose of this function is to load the related PO from the Transfer Order, then load the related inventory transfer to check a box. function checkSentBox(rec, rectype) { var createdFromPoId = rec.getValue('custbody_createdfrom_po'); log.debug('PO: ', createdFromPoId); var poRec = record.load({ type: record.Type.PURCHASE_ORDER, id: createdFromPoId, isDynamic: false     });     var invTransferId = poRec.getValue({fieldId: 'custbody_inv_transfer'}); log.debug('IT: ', invTransferId);     var invTransfer = record.load({     type: record.Type.INVENTORY_TRANSFER,     id: invTransferId,     isDynamic: false });     invTransfer.setValue({fieldId: 'custbody_received', value: true});     invTransfer.save({ ignoreMandatoryFields: true }); }
e
Is
record
defined? Wrap it all in a try/catch and log any errors
l
Yes, it's defined globally.
b
what type of script is this?
l
User event.
b
you should just be able to remove all the try catches, the error will be logged as a system level log
l
It doesn't log any error.
b
what does all your code look like
l
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */

define(['N/record'],(record) => {

const afterSubmit = (scriptContext) => {
var rec = scriptContext.newRecord;

function checkSentBox(rec, rectype) {
	
	try {
var createdFromPoId = rec.getValue('custbody_createdfrom_po');
log.debug('PO: ', createdFromPoId);

var poRec = record.load({
                        type: record.Type.PURCHASE_ORDER,
                        id: createdFromPoId,
                        isDynamic: false
    });

    var invTransferId = poRec.getValue({fieldId: 'custbody_inv_transfer'});
log.debug('IT: ', invTransferId);

    var invTransfer = record.load({
    type: record.Type.INVENTORY_TRANSFER,
    id: invTransferId,
    isDynamic: false
});

    invTransfer.setValue({fieldId: 'custbody_received', value: true});

    invTransfer.save({
                ignoreMandatoryFields: true
            });

} catch (error) {
log.error('ERROR in updating the IT', error.name + ': ' + error.message)
}
}


        return { 
            afterSubmit
        }
    });
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(['N/record'],(record) => {
    
Copy code
const afterSubmit = (scriptContext) => {
    var rec = scriptContext.newRecord;
Copy code
function checkSentBox(rec, rectype) {
    
    try {
var createdFromPoId = rec.getValue('custbody_createdfrom_po');
log.debug('PO: ', createdFromPoId);
Copy code
var poRec = record.load({
                        type: record.Type.PURCHASE_ORDER,
                        id: createdFromPoId,
                        isDynamic: false
    });
Copy code
var invTransferId = poRec.getValue({fieldId: 'custbody_inv_transfer'});
log.debug('IT: ', invTransferId);
Copy code
var invTransfer = record.load({
    type: record.Type.INVENTORY_TRANSFER,
    id: invTransferId,
    isDynamic: false
});
invTransfer.setValue({fieldId: 'custbody_received', value: true});
Copy code
invTransfer.save({
                ignoreMandatoryFields: true
            });
Copy code
} catch (error) {
    log.error('ERROR in updating the IT', error.name + ': ' + error.message)
}
    }
Copy code
return { 
            afterSubmit
        }
    });
b
that code shouldnt do anything
it never calls checkSentBox
l
Thanks for your help. Actually, it was a very long script. I took away the parts that were working which I did incorrectly. But it's fine now.