Hello everyone, I'm working on fetching files atta...
# suitescript
s
Hello everyone, I'm working on fetching files attached to a customer. I’ve created a search that displays results in the UI, but the count returns as 0 in the script. I’m using
search.load
in a Restlet. Any insights on this issue would be greatly appreciated!
a
share your code
s
Hi @Anthony OConnor I have tried both of these code blocks both are giving 0 count. Snippet 1:var searchObj = search.load({ id: request.searchID }); var searchResultCount = searchObj.runPaged().count; log.debug("searchObj result count", searchResultCount); Snippet 2: var customerSearchObj = search.create({ type: "customer", filters: [ ["file.name","isnotempty",""], "AND", ["internalid","anyof","8799"] ], columns: [ search.createColumn({ name: "internalid", join: "file", label: "Internal ID" }), search.createColumn({ name: "name", join: "file", label: "Name" }), search.createColumn({name: "internalid", label: "Internal ID"}) ] }); var searchResultCount2 = customerSearchObj.runPaged().count; log.debug("searchResultCount2 result count",searchResultCount2);
a
difficult to debug the first one without knowing what the search looks like. the 2nd one, it looks like you're doing a customer search and trying to join to "file"? There's no joining of customer to file. https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2023_2/script/record/customer.html
actually record browser is just missing this.
so ignore the above
s
Hi @Anthony OConnor Criteria for search: SS1 Columns: SS2 Result in UI: SS3
a
Copy code
let filters = [
    search.createFilter({
        name: 'internalid',
        operator: search.Operator.ANYOF,
        values: recId
    }),
    search.createFilter({
        name: 'internalidnumber',
        join: 'file',
        operator: search.Operator.ISNOTEMPTY
    })
];

let fileSearch = search.create({
    type: recType,
    filters: filters,
    columns: [
        search.createColumn({
            name: 'internalid',
            join: 'file'
        }),
        search.createColumn({
            name: 'documentsize',
            join: 'file'
        }),
        search.createColumn({
            name: 'name',
            join: 'file'
        })
    ]
});
this code is workign for me and the only difference I'm seeing is the isnotempty filter against internalidnumber instead of filename
s
Thankyou so much let me try this once.
a
this is generic and not specific to customer tho so just replace recType with customer 🙂
and obv. enter your recId value for testing purposes
s
It is still giving 0 results seems like some bug.
a
hmm yeah sorry I don't know, this seems weird
s
Code after changes"let filters = [ search.createFilter({ name: 'internalid', operator: search.Operator.ANYOF, values: 8799 }), search.createFilter({ name: 'internalidnumber', join: 'file', operator: search.Operator.ISNOTEMPTY }) ]; let fileSearch = search.create({ type: "customer", filters: filters, columns: [ search.createColumn({ name: 'internalid', join: 'file' }), search.createColumn({ name: 'documentsize', join: 'file' }), search.createColumn({ name: 'name', join: 'file' }) ] });"
Thankyou for help @Anthony OConnor
a
that code is part of my suiteapp so I trust it works, what does your code to get the number of results look like?
s
Copy code
var customerSearchObj = search.create({
            type: "customer",
            filters:
            [
               ["file.name","isnotempty",""],
               "AND",
               ["internalid","anyof","8799"]
            ],
            columns:
            [
               search.createColumn({
                  name: "internalid",
                  join: "file",
                  label: "Internal ID"
               }),
               search.createColumn({
                  name: "name",
                  join: "file",
                  label: "Name"
               }),
               search.createColumn({name: "internalid", label: "Internal ID"})
            ]
         });
         var searchResultCount2 = customerSearchObj.runPaged().count;
         log.debug("searchResultCount2 result count",searchResultCount2);
Hi @Anthony OConnor It's weird i had used similar searches earlier but never faced such issue.
a
1. is customer 8799 inactive? 2. should 8799 be a number instead of a string?
s
Yes that customer is active. And i tried both via string and number.
a
you're testing this in your restlet?
and you're getting the log.debug result as 0?
s
Yes, It is part of a integration with a python server.
a
1. test the suitescript code in the console, so not using the restlet at all and confirm it works there
if it does work there, but doesn't work in the restlet... I'd look at permissions / roles on the restlet auth
if the role used by the restlet has idk subsidiary restrictions for example and this customer doesn't live in the same subsidiary as the role that's triggering the restlet you might get zero results
Are you familiar with running suitescript code in the console?
first go to any record page in the NetSuite UI hit F12 to open dev tool, then run the following code in the console to load the SS2.0 modules.
Copy code
require(['N'], function(N) {
for(var n in N){window[n] = N[n];};
});
then just paste your SS2.0 code into the console and run it
image.png
i removed the customer id filter, and added a random file to a random customer.... now i get 1 result
image.png
s
Hi @Anthony OConnor Thank you so much! It turns out it was a role permission issue my mistake! I spent the whole day working on the Python service, and I overlooked it. Haha, I think I need a break now. Again, I really appreciate your help; you saved my day!
🙌 1
👍 1
a
happy to help rubber duck debugging
🎉 1