Connecting Sales order with Credit memo.

User event script with afterSubmit entry point is used.

//Connecting sales order with Credit memo
let currentRecord = scriptContext.newRecord
log.debug("currentRecord", currentRecord)
let cmSelected = currentRecord.getValue({  // "Related credit memo" field in sales order
    fieldId: 'custbodyjj_credit_memo'
});                        
let cmRecord = record.load({
    type: record.Type.CREDIT_MEMO,
    id: cmSelected,
    isDynamic: false
})
log.debug("cmRecord", cmRecord)
log.debug("recordId", currentRecord.id);
cmRecord.setValue({                      // "Applying sales order" field in credit memo
    fieldId: 'custbody_jj_applyso',
    value: currentRecord.id
});
cmRecord.save({
   ignoreMandatoryFields: true,
   enableSourcing: false
});

Leave a comment

Your email address will not be published. Required fields are marked *