Hi, I am trying to create a saved search within a...
# suitescript
j
Hi, I am trying to create a saved search within a suitescript and filter it on trandate. I declare my variable (it is correctly declared, I can update a transaction with my variable), but when I do a saved search, I'm not getting any results. This is the filter I am using: ["trandate","onorafter",myVariable] If I hardcode my date, everything works fine. ["trandate","onorafter",'2022-01-01'] Any ideas?
a
You are probably a date(object) to update the transaction and that is fine, but you need to convert that date(Object) to string to use it as a filter in a saved search, that is why is working when you hardcode the value(string) in your example.
j
Ah, alright, thank you! Do you know how I do that?
w
format.format() could do it
j
Thanks!
Guess like: ["trandate","onorafter",format.format({value:myVariable, type: format.Type.STRING}) ]
w
Copy code
format.format({
    value: myVariable, //if myVariable is a date-object
    type: format.Type.DATE
})
j
OK, so that is formatting it to a string?
w
A good way to find out is to test it in the browser console (when on a record page):
Copy code
require(['N/format'], function(format) {
    console.log(format.format({
        value: new Date(),
        type: format.Type.DATE
    }))
})
🙌 1