Hello, i'm trying to create a search in a script f...
# suitescript
h
Hello, i'm trying to create a search in a script for deleted Sales Orders records but i have a hard time figuring out the filters, particularly Record Type is 'Sales Orders' and a column of internal id of deleted records to send to an external system. Any advice is much appreciated.
this is what i have so far, but the 'type' is invalid
var salesOrderSearchObj = search.create({
            type: search.Type.DELETED_RECORD,             filters:             [                 ["deleteddate","within","today"],                  // "AND",                  // ["type","anyof","SalesOrd"],              ]         });
b
have you created the search in the ui?
h
yes i have
message has been deleted
message has been deleted
i used the plugin but it says "export as script not supported"
b
load the search in code
and log the filter expression
h
thanks @battk. but for some reason it returns 0 count even though there's one result
b
what was the filter expression
h
[{"name":"deleteddate","operator":"within","values":["today"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0},{"name":"recordtype","operator":"anyof","values":["salesorder"],"isor":false,"isnot":false,"leftparens":0,"rightparens":0}]
basically only two filters as screenshot above. I just don't understand why even loading a saved search, it doesn't give correct results
b
sounds like a permission issue
h
i have an admin right. What other permissions should i ask for?
b
as in the script is running using the administrator role?
h
yes it's running using the admin role
b
you can try running it in the debugger
s
I deleted a sales order, and ran the search in UI and console, returns same number of results
Copy code
let results = search.create({
    type: search.Type.DELETED_RECORD,
    filters: [
        ['recordtype', 'anyof', 'salesorder'],
        'AND',
        ['deleteddate', 'onorafter', 'today']
    ],
    columns: [
        'deleteddate',
        'deletedby',
        'recordtype',
        'name'
    ]
}).run().getRange(0,1000).map(res => res.toJSON())
produces results for me
h
@Sandii thanks, it works now. Do you know if there's a way to get Sales Orders Internal ID?
s
it's not there any more so no I don't believe so
h
oh okay thanks
s
If you need to retain internal id's on delete, you should script on Delete of those records and write that down some where.
There is a specific entry point on UserEvent for DELETE
h
thanks i'll look into that