I want to delete all transactions based on a suite...
# suitescript
w
I want to delete all transactions based on a suiteQL. Are there any built in functions to get the transaction type as record.Type/equivivalent from a suiteQL? I think I have seen this being discussed previously, but can't find anything fitting. BUILTIN.CF and .DF just gives me the 'ExpRept' and 'Expense Report' values respectively
n
Just poking around, you may be able to do something with the table ScriptRecordType maybe a join on the name with the value of builtin.df to the name column and get the internalid Im not sure if you can replace the type parameter of record.delete() with an internalid though. Would be worth testing though
c
@Watz Have you tried the field
recordtype
?
💯 2
w
Thanks to both of you! @Clay Roper, that's exactly right
🙌 2
t
@Watz I have an app that can do this via Saved search and was thinking of adding a SuiteQL feature to it. I'll have to add this to the backlog
w
@The Usual Suspect this is being used as a button function to delete transactions related to a custom record. So it should only delete a handful of transactions.
Copy code
require(['N/record','N/query'], function(record, query) {
    query.runSuiteQL({
        query: `
            SELECT id, recordtype as type
            FROM transaction
            WHERE 
                custbody_related_record = ${newRecord.id}
                AND isreversal = 'F'`
    }).asMappedResults().forEach(result => record.delete(result))
})
👍 3
t
Very cool. I'll have to save this snippet