I am trying to create and save a journal via a Sui...
# suitescript
k
I am trying to create and save a journal via a Suitelet. I am receiving the error: "You must enter at least one line item for this transaction" I simplified and removed all custom fields and am just populating the necessary fields. I am logging out each step and each step is being logged. I also logged out the line count before saving and it returns the amount of lines I am trying to enter (2). I also attempted using the same data and creating a journal via the UI. It saved with no issue. Does anyone see where it going wrong? The code is below:
Copy code
const je = record.create({ type: record.Type.JOURNAL_ENTRY, isDynamic: true });
            je.setValue('trandate', new Date('1/20/2024'));
            je.selectNewLine({
              sublistId: 'line'
            });
            je.setCurrentSublistValue({
              sublistId: 'line',
              fieldId: 'account',
              value: 123,
              ignoreFieldChange: false
            });
            log.debug(TAG, 'Account Set');
            je.setCurrentSublistValue({
              sublistId: 'line',
              fieldId: 'credit',
              value: 2.87,
              ignoreFieldChange: false
            });
            log.debug(TAG, 'Amount Set: ' + 2.87);

            je.commitLine({
              sublistId: 'line',
              ignoreRecalc: true
            });
            log.debug(TAG, 'Line Committed');
            je.selectNewLine({
              sublistId: 'line'
            });
            je.setCurrentSublistValue({
              sublistId: 'line',
              fieldId: 'account',
              value: 123,
              ignoreFieldChange: false
            });
            log.debug(TAG, 'Account Set');
            je.setCurrentSublistValue({
              sublistId: 'line',
              fieldId: 'debit',
              value: 2.87,
              ignoreFieldChange: false
            });
            log.debug(TAG, 'Amount Set: ' + 2.87);

            je.commitLine({
              sublistId: 'line',
              ignoreRecalc: true
            });
            log.debug(TAG, 'Line Committed 2');
            
            const lineCount = je.getLineCount({ sublistId: 'line' });
            log.debug(TAG, `Total Lines Added: ${lineCount}`);
            log.debug(TAG, 'Period: ' + je.getValue('postingperiod'));
            const jeId = je.save({ enableSourcing: true, ignoreMandatoryFields: true });
j
Your code looks fine from what I can tell, but maybe there is something missing. Things I would suggest. 1. Run the script as an administrator to make sure there isn't some permissions issues blocking the run 2. See if your account instance has some other mandatory native fields (i.e. Subsidiary, Currency, Posting Period, or Department 3. Add a try catch to see if you can get a better log like:
Copy code
try { const jeId = je.save({ enableSourcing: true, ignoreMandatoryFields: true }); log.debug(TAG, `Journal Entry Saved: ${jeId}`); } 
catch (e) { log.error(TAG, `Error saving journal entry: ${e.message}`); }
k
Thank you for your response! I have already tried 1 & 3, it returns the same error and I was thinking I would catch the mandatory fields when I attempted in the UI but it saved just fine. Will look deeper to see if I am missing any mandatory fields. Thanks again for the response!
b
dont use ignoreRecalc
🎉 1
k
@battk Oh wow, that was it. Thank you so much!!