```function getCurrentAccountBalance(account, amaz...
# suitescript
n
Copy code
function getCurrentAccountBalance(account, amazonMarketplace, date) {
      let num_amount = 0;
      let first_date = date.slice(0, -2) + '01';
      log.debug('The first date is: ', first_date);
      log.debug('The date is: ', date);
      log.debug('Amazon marketplace is: ', amazonMarketplace);
      log.debug('The account is: ', account);

      //JE Search
      let transactionSearchObj = SEARCH.create({
        type: "transaction",
        filters: [
          ["systemnotes.type", "is", "T"],
          "AND",
          ["posting", "is", "T"],
          "AND",
          ["trandate", "within", first_date, date],
          "AND",
          ["account", "anyof", account],
          "AND",
          ["custbodyrsm_journal_type","noneof","5"],
          "AND",
          ["cseg1.name", "is", amazonMarketplace]
        ],
        columns: [
          SEARCH.createColumn({
            name: "account",
            summary: "GROUP",
            label: "Account"
          }),
          SEARCH.createColumn({
            name: "amount",
            summary: "SUM",
            label: "Amount (CAD)"
          }),
          SEARCH.createColumn({
            name: "fxamount",
            summary: "SUM",
            label: "Amount (FX)"
          }),
          SEARCH.createColumn({
            name: "currency",
            summary: "GROUP",
            label: "Currency"
          }),
          SEARCH.createColumn({
            name: "cseg1",
            summary: "GROUP",
            label: "Marketplace"
          })
        ]
      });

      let searchResultCount = transactionSearchObj.runPaged().count;
      log.debug("transactionSearchObj result count", searchResultCount);

      transactionSearchObj.run().each(function(result) {
        num_amount += parseFloat(result.getValue({
          name: 'fxamount',
          summary: "SUM"
        }));
        log.debug('The amount of the current account balance is: ', num_amount);
        return true;
      });

      return num_amount;
    }
This returns 0 results every time - any clues why? I have a feeling its the criterias...
m
Build the search in UI and then convert to code using chrome extension.
n
that's what I did
I then replaced the criterias with some variables
m
What's the point of the system notes criteria?
Also why don't you remove the groups and just sum once in the search?
n
it get exact account balance this way -> systemnotes.type (create) = true also, I could but I built it in UI so I took the code as is
m
I'm not really getting the system notes part. Do you get a different balance if you remove it?
n
yes
its a great way to get exact account balances that match the P&L and BS
m
it's not really related to your question but i'm struggling to understand why that is the case. what do you mean by exact?
in terms of your question, are all your variables internal ids? and date format matches what was exported from the search?
n
so I don't know about you but if you ever wanted to get the amount in a specific account through a saved search, it can be challenging. for some reason, if you have this set of criteria, you get exact amounts per account (trick I learned a while back)
so the variable are internal ID's, but for first_date I am putting the date together so to speak
Copy code
2	View	Debug	transactionSearchObj result count	2020-10-26	5:44 PM	-System-	0	Remove
3	View	Debug	The account is:	2020-10-26	5:44 PM	-System-	627	Remove
4	View	Debug	Amazon marketplace is:	2020-10-26	5:44 PM	-System-	3	Remove
5	View	Debug	The date is:	2020-10-26	5:44 PM	-System-	2020-02-29	Remove
6	View	Debug	The first date is:	2020-10-26	5:44 PM	-System-	2020-02-01	Remove
7	View	Debug	The search result for amazon account is:	2020-10-26	5:44 PM	-System-	627	Remove
8	View	Debug	The amazon account to be set on the journal line is:	2020-10-26	5:44 PM	-System-	627	Remove
9	View	Debug	The account is:	2020-10-26	5:44 PM	-System-	1177	Remove
10	View	Debug	Amazon marketplace is:	2020-10-26	5:44 PM	-System-	11	Remove
11	View	Debug	The date is:	2020-10-26	5:44 PM	-System-	2020-02-29	Remove
12	View	Debug	The first date is:	2020-10-26	5:44 PM	-System-	2020-02-01	Remove
13	View	Debug	The search result for amazon account is:	2020-10-26	5:44 PM	-System-	1177	Remove
14	View	Debug	The amazon account to be set on the journal line is:	2020-10-26	5:44 PM	-System-	1177	Remove
15	View	Debug	Reversal date	2020-10-26	5:44 PM	-System-	Sun Mar 01 2020 00:00:00 GMT-0800 (PST)	Remove
16	View	Debug	Reversal date	2020-10-26	5:44 PM	-System-	Sun Mar 01 2020 00:00:00 GMT-0800 (PST)	Remove
17	View	Debug	amount	2020-10-26	5:44 PM	-System-	-5696.66	Remove
18	View	Debug	exch rate	2020-10-26	5:44 PM	-System-	1	Remove
19	View	Debug	marketplace	2020-10-26	5:44 PM	-System-	3	Remove
20	View	Debug	account	2020-10-26	5:44 PM	-System-	627	Remove
21	View	Debug	amount	2020-10-26	5:44 PM	-System-	-4.99	Remove
22	View	Debug	exch rate	2020-10-26	5:44 PM	-System-	.93869	Remove
23	View	Debug	marketplace	2020-10-26	5:44 PM	-System-	11	Remove
24	View	Debug	account	2020-10-26	5:44 PM	-System-	1177	Remove
25	View	Debug	Current Object	2020-10-26	5:44 PM	-System-	2020-02-29 5 Fri Feb 28 2020 16:00:00 GMT-0800 (PST)	Remove
its probably something really easy im missing here but it returns 0 results and im positive there are results
m
if you run the exported search from the ui you get results? I would log the filters object you create and compare it against that
n
You mean just hardcode the UI search and put it in there?
in the script that is
b
If you think its the filters, then start removing filters until you get results
m
yes just hardcode the UI search, confirm you are getting results, and then compare to your modified version
or battks suggestion
n
alright will do
m
i still don't get this need for the system notes filter
b
I vote the trandate filter first
n
alright ill report back
m
i tried a saved transaction search in my account with the only criteria posting = true, and grouped by account, summed amount
every account i checked is spot on to the COA and BS
n
maybe I was mistaken !
m
if you were looking at system notes elsewhere in results/criteria i could understand why not having it there would cause results to be duplicated