I have a weird issue, I am trying to sync journals...
# suitescript
m
I have a weird issue, I am trying to sync journals with the client's system, but the lines of the journals doesn't match the order... I fetch the unsynced lines, get their
line
field, select that, get the info I want, then mark it as synced. But in this case, I actually end up selecting the next line...
b
what does the code look like
m
Searching to fetch the unsynced lines
Copy code
// fetch the lines
var src = search.create({
        type: "journalentry",
        columns: ["line", "entity", "memo", "amount"],
        filters: [
          search.createFilter({
            name: "internalid",
            operator: <http://search.Operator.IS|search.Operator.IS>,
            values: journalID,
          }),
          search.createFilter({
            name: "custcol_edc_journal_line_synced",
            operator: <http://search.Operator.IS|search.Operator.IS>,
            values: false,
          }),
          search.createFilter({
            name: "debitamount",
            operator: search.Operator.ISNOTEMPTY,
            values: false,
          }),
        ],
      });
var lines = src.run().getRange({ start: 0, end: 50 });
Then, loop over the lines, first get the value of
line
select that line, get the values, and mark it as synced and commit
Copy code
let lineNum = lines[i].getValue("line");
journal.selectLine({
          sublistId: "line",
          line: lineNum,
        });
payload["amount"] = Math.abs(
          journal.getCurrentSublistValue({
            sublistId: "line",
            fieldId: "debit",
          })
        );
journal.setCurrentSublistValue({
          sublistId: "line",
          fieldId: "custcol_edc_journal_line_synced",
          value: true,
          ignoreFieldChange: true,
        });

        journal.commitLine({
          sublistId: "line",
        });
b
the line column's full name is line id
the line id is often the same as the line number, but its not required to be
m
let me try...
b
the temptation will be to use the line sequence number instead
resist it, the line id is more resistant to lines being deleted or inserted
use Record.findSublistLineWithValue instead to find the matching line
m
use Record.findSublistLineWithValue instead to find the matching line
That would require having a unique value for each line, right?
b
the line id is unique
m
oh, I got it now, let me try again...
Worked 🙌
Thanks ❤️