Here is the code ```const vendorPaymentRec = trans...
# suitescript
i
Here is the code
Copy code
const vendorPaymentRec = transformRecord('vendorbill', context.newRecord.id, 'vendorpayment');
setVendorPaymentData(vendorPaymentRec, jeId, data, context.newRecord.id);

const transformRecord = (fromType, fromId, toType) => {
    const fn = 'transformRecord';
    let rec = {};
    try {
        rec = record.transform({
            fromType,
            fromId,
            toType,
            isDynamic: true,
        });
    } catch (error) {
        log.error({ title: `Error: ${fn}`, details: error });
    }
    return rec;
};

const setVendorPaymentData = (rec, jeId, data, vbId) => {

    try {

        // Header data
        rec.setValue({ fieldId: 'entity', value: data.vendor, ignoreFieldChange: false });
        const lineCount = rec.getLineCount({ sublistId: 'apply' });
        log.audit({ title: 'linecount', details: lineCount });
        // Apply lines data
        for (let i = 0; i < lineCount; i++) {

            const id = rec.getSublistValue({ sublistId: 'apply', fieldId: 'internalid', line: i });

            if (Number(id) === Number(vbId)) {
                rec.selectLine({ sublistId: 'apply', line: i });
                rec.setCurrentSublistValue({
                    sublistId: 'apply',
                    fieldId: 'apply',
                    value: true,
                });
                rec.commitLine({ sublistId: 'apply' });
            }
            if (Number(id) === Number(jeId)) {
           
                rec.selectLine({ sublistId: 'apply', line: i });
                rec.setCurrentSublistValue({
                    sublistId: 'apply',
                    fieldId: 'apply',
                    value: true,
                });
                rec.commitLine({ sublistId: 'apply' });
            }
        }
        try {
            let recId = rec.save({
                enableSourcing: true,
                ignoreMandatoryFields: false,
            });

        } catch (error) {
            log.audit({ title: 'ERROR: Vendor Payment ', details: error });
        }
        
    } catch (error) {
        log.error({ title: `Error: ${fn}`, details: error });
    }
};