Hi Suitescript experts, is there a way to search f...
# suitescript
h
Hi Suitescript experts, is there a way to search for an exact file name? I'm using a saved search but it returns multiple results. For example, customerCode is "ABC" but it also returns "ABC1", "ABC2", etc.,
Copy code
let folderSearchObj = search.create({
                    type: "folder",
                    filters:
                        [
                            ["internalid","anyof", CONSTANTS.folder],
                            "AND",
                            ["file.name","haskeywords",customerCode]

                        ],
                    columns:
                        [
                            search.createColumn({
                                name: "name",
                                join: "file",
                                label: "File Name"
                            }),
                            search.createColumn({
                                name: "internalid",
                                join: "file",
                                label: "File ID"
                            })
                        ]
                });
e
Why are you using
file.name
haskeywords
insted of
is
?
Copy code
["name","is","F-32828.pdf"]
Copy code
var fileSearchObj = search.create({
   type: "file",
   filters:
   [
      ["name","is","F-32828.pdf"]
   ],
   columns:
   [
      search.createColumn({
         name: "name",
         sort: search.Sort.ASC
      }),
      "folder",
      "documentsize",
      "url",
      "created",
      "modified",
      "filetype"
   ]
});
๐Ÿคจ 1
thanks 1
a
you should just be able to change this
["file.name","haskeywords",customerCode]
to this
["file.name","is",customerCode]
but you may need to add the extension to get matches .csv .txt .pdf w/e
h
The full file name is pretty long: "SUSAN_Customer_Statement.csv"
a
@Edgar Valdes we can do file searches now? I thought we only had folder searches with joins to files?
h
So if I use "is", it would not return anything
a
do you have solid naming convention? if so just add the _ to the customer code?
if you have ABC_stuffs ABC2_stuffs ABC3_stuffs then you can search for ABC_ instead of ABC and use haskeywords, or contains?
thanks 1
e
Yes @Anthony OConnor, this is a real search, here in the browser console
a
sweet, they must have added that pretty recently, based on how quickly you had it available I figured it must be working code ๐Ÿ™‚
e
Tested with a 53 character long file name, it works just fine
h
@Anthony OConnor I've tried "haskeywords" : "SUSAN_" and it still returns multiple results
a
what are the file names of the results?
h
Something like this: SUSAN_Customer_Statement.csv SUSAN1_Customer_Statement.csv
The only difference is the first part before the underscore. The rest stays the same
a
i'm not that familiar with haskeywords, does contains give you the same thing?
hmm or i guess you can try startswith too?
startswith is probably more performant of the 3 tbh
provided you know, it actually starts with that ๐Ÿ˜„
h
"contains" gives the same results, so does "startswith"
a
blinkingguy
h
Anyway, i found another solution by using the File Description
a
I'm wondering if the search filter is using the
_
as like a wildcard or something? is that a thing maybe?
ok good you found a workaround... alternative would be to get all the dumb results, and then filter yourself in the JS by applying the same startsWith logic in native JS
h
Yea that would be another alternative. Thanks for all your help @Anthony OConnor and @Edgar Valdes
๐Ÿ‘ 1
e
You should probably create the search in the UI until you get it right. Then build it in script. You can even use one of the Chrome Extensions to export saved search to script (there are at least two of them out there)