I am trying to figure out how to loop through all ...
# suitescript
c
I am trying to figure out how to loop through all the Bills on a Bill Payment Transaction search. Using the appliedToTransaction join I am able to get some bill information, but only on the first bill of a bill payment. How can I go about iterating all bills on a bill payment?
b
the applied to transaction join should get you all the bills on a bill payment
what do your filters and columns look like?
c
I am currently using these filters. The internalId I am using I know has multiple bills so i have been working off of that.
Copy code
var filters = [

                search.createFilter({
                    name: 'type',
                    operator: <http://search.Operator.IS|search.Operator.IS>,
                    values: 'VendPymt'
                }),

                search.createFilter({
                    name: 'internalid',
                    operator: <http://search.Operator.IS|search.Operator.IS>,
                    values: 10617

                }),
                search.createFilter({
                    name: 'mainline',
                    operator: <http://search.Operator.IS|search.Operator.IS>,
                    values: "F"
                })

     ];
b
columns
although to be honest, none of those filters should prevent your search results from having multiple rows
c
Copy code
var billSearch = search.create({
                type: search.Type.VENDOR_PAYMENT,
                columns: [{
                    name: 'entity',
                },{
                    name: 'tranid'
                },{
                    name: 'amount'
                },{
                    name: "appliedtolinkamount",

                },{
                  name: 'trandate'
                },{
                    name: "custbody_csiinvoiceid",
                    join: "appliedToTransaction",
                    label: "csiInvoiceId"

                },{
                    name: "trandate",
                    join: "appliedToTransaction",
                    label: "billDate"
                },{
                    name: "termsdiscountamount",
                    join: "appliedToTransaction"
                },{
                    name: "termsdiscountdate",
                    join: "appliedToTransaction"
                },{
                    name: 'appliedtotransaction'
                }],
                filters: filters
            });
In this case I am searching for a single Bill Payment. So, I expect 1 result. But, is there a field I need to loop over in order to get the associated Bills for the payment?
b
you should have multiple search results
each row representing a different applied to transaction (hopefully bills in this case)
c
Interesting.
b
you may want to try creating the search in the ui first to see the multiple rows thing
c
Yea, I have tried that too. I do get multiple rows back. That's how I started piecing my search script together too.
b
you can share the code you are using to get and iterate through your search results and i can tell you if anything unusual is being done
c
That'd be excellent. Give me a second and I'll clean it up.
Thanks for taking a look!
Copy code
The callback function takes a search.Result object as an input parameter and returns a boolean which can be used to stop the iteration with a value of false, or continue the iteration with a value of true.
make your callback to each return true
c
oh my god, that can't be it!!!
Jeez, that was it. Thank you so much!
b
you can also probably remove the lookupFields by using the vendor join
c
Sounds good. Thanks!
These transaction searches are not easy to figure out. If it wasn't for the Chrome extension to Export the scripts from a Saved Search I would never know the column names. At least I don't see the same column names in the record browser anywhere. For example termsdiscountdate etc... Or, am I missing them in the documentation somewhere?
b
i generally don't bother with the record browser for searches. Build the search in the ui first, and then transform it into code
c
OK, thanks for the tip