I am trying to pay a vendor bill using a bill paym...
# suitescript
a
I am trying to pay a vendor bill using a bill payment that would utilize a journal entry to offset the payment amount via script. I am not encountering any errors in the script and I am aware that no bill payment transactions are created since the journal entry is used for payment. while there are no errors encountered trying to save the bill payment transaction, the vendor bill transaction's amount due is not reduced and the journal entry is not applied. what could have went wrong here? do note that when manually doing this process, the journal entry gets applied to the vendor bill and it's due gets reduced.
a
you didn't share you code how could we possibly diagnose your issue???
I'm going to assume there's nothing wrong with your JE creation and just need to apply it. You have to create a a payment record in suitescript, ultimately it WONT create a customer payment but you have to leverage that in suitescript to use the JE as the payment.... here's the sample code.
Copy code
const payment = record.transform({
                fromType: record.Type.INVOICE,
                fromId: invoiceId,
                toType: record.Type.CUSTOMER_PAYMENT,
                isDynamic: true
            });
            // Find and update the apply line for our invoice
            const applyCount = payment.getLineCount({ sublistId: 'apply' });
            for (let i = 0; i < applyCount; i++) {
                const doc = payment.getSublistValue({
                    sublistId: 'apply',
                    fieldId: 'doc',
                    line: i
                });
                if (doc === invoiceId) {
                    payment.selectLine({
                        sublistId: 'apply',
                        line: i
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'apply',
                        fieldId: 'apply',
                        value: true
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'apply',
                        fieldId: 'amount',
                        value: creditAmount
                    });
                    payment.commitLine({
                        sublistId: 'apply'
                    });
                    break;
                }
            }
            // Find and update credit line for the journal entry
            const creditCount = payment.getLineCount({ sublistId: 'credit' });
            for (let i = 0; i < creditCount; i++) {
                const doc = payment.getSublistValue({
                    sublistId: 'credit',
                    fieldId: 'doc',
                    line: i
                });
                if (doc === journalId.toString()) {
                    payment.selectLine({
                        sublistId: 'credit',
                        line: i
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'credit',
                        fieldId: 'apply',
                        value: true
                    });
                    payment.setCurrentSublistValue({
                        sublistId: 'credit',
                        fieldId: 'amount',
                        value: creditAmount
                    });
                    payment.commitLine({
                        sublistId: 'credit'
                    });
                    break;
                }
            }
            // this is a NetSuite magic trick: calling .save() on a payment
            // record where the attached invoice has a journal entry that
            // cancels out the G/L impact will mark the Invoice as PAID
            const paymentId = payment.save();
            log.debug('Created customer payment', { paymentId });
            return paymentId;
        }
oh this is for a JE paying a customer invoice with a customer payment, but just flip everything to the AP versions and it should be the same
double check the sublist names on the bill payment record
a
my bad, let me add the code snippet here: here's the snippet that creates the journal entry for offset:
Copy code
const make_je_record = record.create({
    type: 'journalentry',
    isDynamic : true,
    defaultValues: { subsidiary: chosenSubsidiary }
});
make_je_record.setValue({ fieldId: 'custbody_ct_240830_jetype', value: 5 }); // JOURNAL TYPE =  OTHERS
make_je_record.setValue({ fieldId: 'currency', value: chosenCurrency });
make_je_record.setValue({ fieldId: 'approvalstatus', value: 2 }); // APPROVAL STATUS = APPROVED
make_je_record.setValue({ fieldId: 'custbody_ct_240830_crtd_fr_apar_offst', value: true });

make_je_record.selectNewLine({sublistId: "line"});
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "account", value: chosenArAccount });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "credit", value: parseFloatOrZero(currentArTotal) });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "entity", value: chosenCustomer} );
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "department", value: chosenDepartment });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ct_240830_clss", value: chosenCostCenter });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ful_site", value: chosenSite });
make_je_record.commitLine({sublistId: "line"});

make_je_record.selectNewLine({sublistId: "line"});
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "account", value: chosenApAccount });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "debit", value: parseFloatOrZero(currentApTotal) });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "entity", value: chosenVendor} );
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "department", value: chosenDepartment });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ct_240830_clss", value: chosenCostCenter });
make_je_record.setCurrentSublistValue({sublistId: "line", fieldId: "cseg_ful_site", value: chosenSite });
make_je_record.commitLine({sublistId: "line"});

const created_je_id = make_je_record.save({ enableSourcing: true, ignoreMandatoryFields: true });
log.emergency('created_je_id', created_je_id);

const je_obj = {};
je_obj.transactionId = created_je_id;
je_obj.transactionType = 'journalentry';
je_obj.paidAmount = parseFloatOrZero(currentApTotal);
billsPaymentArray
data:
Copy code
[{"transactionId":"1696348","transactionType":"vendorbill","paidAmount":1.12}]
here's the snippet that transforms each vendor bill ticked on a custom UI.
Copy code
billsPaymentArray.forEach((billPayment) => {
    const make_billPayment_record = record.transform({
        fromType: billPayment.transactionType,
        fromId: billPayment.transactionId,
        toType: record.Type.VENDOR_PAYMENT,
        isDynamic: true
    });
    make_billPayment_record.setValue({ fieldId: 'apacct', value: chosenApAccount, ignoreFieldChange: false });
    make_billPayment_record.setValue({ fieldId: 'currency', value: chosenCurrency, ignoreFieldChange: false });
    const vendorBillLineNum = make_billPayment_record.findSublistLineWithValue({
        sublistId: 'apply',
        fieldId: 'internalid',
        value: billPayment['transactionId']
    });
    make_billPayment_record.selectLine({
        sublistId: 'apply',
        line: vendorBillLineNum
    });
    make_billPayment_record.setCurrentSublistValue({
        sublistId: 'apply',
        fieldId: 'apply',
        value: true,
        ignoreFieldChange: false
    });
    make_billPayment_record.setCurrentSublistValue({
        sublistId: 'apply',
        fieldId: 'amount',
        value: billPayment['paidAmount'],
        ignoreFieldChange: false
    });
    make_billPayment_record.commitLine({
        sublistId: 'apply'
    });
    const jeLineNum = make_billPayment_record.findSublistLineWithValue({
        sublistId: 'apply',
        fieldId: 'internalid',
        value: je_obj['transactionId']
    });
    make_billPayment_record.selectLine({
        sublistId: 'apply',
        line: jeLineNum
    });
    make_billPayment_record.setCurrentSublistValue({
        sublistId: 'apply',
        fieldId: 'apply',
        value: true,
        ignoreFieldChange: false
    });
    make_billPayment_record.setCurrentSublistValue({
        sublistId: 'apply',
        fieldId: 'amount',
        value: billPayment['paidAmount'] * -1,
        ignoreFieldChange: false
    });
    make_billPayment_record.commitLine({
        sublistId: 'apply'
    });
    log.emergency({
        title: 'setup',
        details: {
            vendorBillLineNum,
            // jeLineNum,
            billPayment
        }
    });
    log.emergency({
        title: 'getvalues',
        details: {
            vbApply: make_billPayment_record.getSublistValue({
                sublistId: 'apply',
                fieldId: 'apply',
                line: vendorBillLineNum
            }),
            jeApply: make_billPayment_record.getSublistValue({
                sublistId: 'apply',
                fieldId: 'apply',
                line: jeLineNum
            }),
            vbAmount: make_billPayment_record.getSublistValue({
                sublistId: 'apply',
                fieldId: 'amount',
                line: vendorBillLineNum
            }),
            jeAmount: make_billPayment_record.getSublistValue({
                sublistId: 'apply',
                fieldId: 'amount',
                line: jeLineNum
            }),
            entity: make_billPayment_record.getValue({
                fieldId: 'entity'
            }),
            subsidiary: make_billPayment_record.getValue({
                fieldId: 'subsidiary'
            }),
            apacct: make_billPayment_record.getValue({
                fieldId: 'apacct'
            }),
            currency: make_billPayment_record.getValue({
                fieldId: 'currency'
            })
        }
    });
    const created_bp_id = make_billPayment_record.save({ ignoreMandatoryFields: true });
    log.emergency('POST_created_bp_id', created_bp_id);
});
I'm not encountering any errors running this script, but the application of payment does not work either
a
does a payment record get created with incorrect apply sublist data? what gets logged at the end for the created_bp_id? just a
0
?
a
both je and vendorbill appear on the sublist and gets applied with negative and positive payment amounts respectively. yes, the
created_bp_id
just gives
0
a
... when you say both appear on the apply sublist with positive and negative amounts... you mean in the UI there's an actual vendor payment record?
cos when you do this on the AR side no customer payment gets created, which is why the ID is 0... but your saying the id is 0 but there IS A vendor payment record?!
is
chosenApAccount
the same account on the JE lines? and is that a valid account for a vendor payment for that entity/sub combination?
a
I mean, when trying to do it manually in the UI, both journal entry and vendor bill appears in the apply sublist. But saving the record would not create a vendor payment since the amount is 0
👍 1
a
I think as a testing step I'd change the amount on the negative apply lines to be 1c less than it should be
Copy code
make_billPayment_record.setCurrentSublistValue({
        sublistId: 'apply',
        fieldId: 'amount',
        value: (billPayment['paidAmount'] * -1)+0.01,
        ignoreFieldChange: false
    });
a
I apply a negative amount on the journal entry then positive amount on the vendor bill, this cancels the amount to 0
a
that way it SHOULD create a bill payment record for 1 cent per line
once you have that bill payment record in the UI you can look at it and what's on there to see if anything looks sus
I assume the extensive logging that you already have suggests everything is fine or you wouldn't be asking
oh is this is a map or reduce stage of a MR? cos if it is you wont get an error without a try /catch
a
this is just done via suitelet
I've tried doing the 1c less to the negative payment application. what I think is sus here is that the journal entry is not appearing on the apply sublist. it should still appear no?
a
if its applied then yes, it should appear on there
if after creating it and it NOT applying the JE should still be available but if its not showing up that would suggest there's an issue with the native AP account on the bill and the line account on the JE that would apply to that side of the GL those accounts have to match
well i'm assuming account it could also be an issue with the vendor / subsidiary too, but I figure that's less likely
a
Yeah, I also tried to not apply it at all on the journal entry. Editing the vendor payment transaction, the journal entry does not show up at all.
I'm gonna ask for a different combination of transaction and I'll report back here if that changes something
a
if the JE created, but its not available to apply on the bill that would suggest there's mismatch on vendor/sub/account between the bill and the JE lines you're trying to apply to the bill
a
isn't it standard for the negative amounts to not show on bill payments when trying to edit them since they are already created in the system?
I've looked further at the transaction where the 1c less to the negative payment application was made. the journal entry is still not applied while the bill payment applies only 1c
we've raised the issue to netsuite support so they can also check if there is something going on
a
is the JE you create via script approved? I see you're setting it to approved in the code, but I'm just wondering if that is actually working
I've been able to recreate the process using your code, and everything checks out
image.png
also FWIW I'm 99% sure you can just remove ALL this code - all that is set appropriately from the initial record transform
a
yes, the created journal entry is approved
have you tried changing the amounts to a different value instead of the default when transforming? i'm suspecting if the change in the payment amount is what's causing this
a
you're doing partial payments?
setting that bill apply line to some other positive amount should be fine... the code above that i highlighted to delete doesn't BREAK anything, it just doesn't DO anything you're resetting values that are already set
a
yes, we're doing partial payments
a
oooh
so you DO want a vendor payment record to be created then? for the balance?
oh n/m, you're adjusting down both lines for the + and - amounts
👍 1
ok i didn't actually test that, but that should also just be fine i think