I switched a seach from SS1 to SS2 and now it cann...
# suitescript
g
I switched a seach from SS1 to SS2 and now it cannot find my filter
Copy code
var locationSearch = search.create({
                    type: 'location',
                    filters: ['internalid', 'anyof', locationId], //Change internal id
                    columns: [
                        search.createColumn({ name: "name", label: "name" }),
                        search.createColumn({ name: "address1", label: "address1" }),
                        search.createColumn({ name: "address2", label: "address2" }),
                        search.createColumn({ name: "city", label: "city" }),
                        search.createColumn({ name: "state", label: "state" }),
                        search.createColumn({ name: "country", label: "country" }),
                        search.createColumn({ name: "zip", label: "zip" }),
                        search.createColumn({ name: "phone", label: "phone" }),
                        search.createColumn({ name: "custrecord_vc_whs_code", label: "custrecord_vc_whs_code" }),
                        search.createColumn({ name: "custrecord_vc_whs_poc", label: "custrecord_vc_whs_poc" }),
                        search.createColumn({ name: "custrecord_vc_whs_poc_phone", label: "custrecord_vc_whs_poc_phone" })
                    ],
                });
b
the only obvious thing that could be wrong is the locationId
k
Update filters to be an array.
[['internalid', 'anyof', locationId]]
g
didnt help
k
How are you getting your variable
locationId
?
g
from the item on the IF
k
can you share your full code in a snippet
g
Copy code
var location_id = 0
                if (transaction_type == 'item fulfillment') {
                    location_id = currTransaction.getSublistValue({ sublistId: 'item', fieldId: 'location', line: 0 });
                } else { //its a PO
                    location_id = currTransaction.getValue({ fieldId: 'location' })
                }
Copy code
var locationSearch = search.create({
                    type: 'location',
                    filters: [['internalid', 'anyof', locationId]], //Change internal id
                    columns: [
                        search.createColumn({ name: "name", label: "name" }),
                        search.createColumn({ name: "address1", label: "address1" }),
                        search.createColumn({ name: "address2", label: "address2" }),
                        search.createColumn({ name: "city", label: "city" }),
                        search.createColumn({ name: "state", label: "state" }),
                        search.createColumn({ name: "country", label: "country" }),
                        search.createColumn({ name: "zip", label: "zip" }),
                        search.createColumn({ name: "phone", label: "phone" }),
                        search.createColumn({ name: "custrecord_vc_whs_code", label: "custrecord_vc_whs_code" }),
                        search.createColumn({ name: "custrecord_vc_whs_poc", label: "custrecord_vc_whs_poc" }),
                        search.createColumn({ name: "custrecord_vc_whs_poc_phone", label: "custrecord_vc_whs_poc_phone" })
                    ],
                });
k
the transaction_type conditional doesnt seem correct to me.
In this case your location is always going to be 0.
well unless it's a PO
g
even when i hardcode the ID it doesnt work
k
Your more than welcome to share your full code here or in a DM. I can review for you.
s
Since you are just retrieving a single Location, and already know the internal id, you could replace the search with lookupFields or even a record load Obviously, it would still be good to understand why the search doesn't work, though. One thing I have found in SS 2.x scripts that seems to be different from older 1.0 scripts, is that permissions can be enforced more strictly. I have some searches that worked fine in 1.0, but when converted to 2.0 or 2.1 I had to add explicit permissions for the record type being searched. It may be worth checking if the role executing the code has the correct permissions for Location.
s
Either way
location_id
!=
locationId
, your variable names dont match
s
@Sandii I didn't even see the lines of code declaring the variable as location_id. Yeah, that would definitely be a problem. I have been using ESLint in my IDE, since it can help catch errors like this (mistyped/undeclared/unused variables)
k
@Sandii Nice catch! didn;t even notice that!
g
the search is in a function where the param passed in is locationId - regardless. thanks @karlenigma it was my If statement.... workin on no sleep is never good
👍 1