getDeleted
In SOAP web services, you can use the getDeleted operation to retrieve a list of deleted records. When you use this operation, you can filter by record type, by script ID, and by the date of record deletion. The getDeleted operation can be useful when you want to synchronize information in a client application with NetSuite.
SOAP Request
The following example shows the usage of the getDeleted operation.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ns="urn:messages_2023_2.platform.webservices.netsuite.com"
xmlns:core="urn:core_2023_2.platform.webservices.netsuite.com">
<soap:Header>
<ns:tokenPassport>...</ns:tokenPassport>
</soap:Header>
<soap:Body>
<ns:getDeleted>
<ns:getDeletedFilter>
<core:deletedDate operator="within">
<core:searchValue>2024-01-01T00:00:00</core:searchValue>
<core:searchValue2>2024-12-31T23:59:59</core:searchValue2>
</core:deletedDate>
<core:type operator="is">
<core:searchValue>salesOrder</core:searchValue>
</core:type>
</ns:getDeletedFilter>
</ns:getDeleted>
</soap:Body>
</soap:Envelope>
SOAP Response
The following sample shows the response to a getDeleted request.
<getDeletedResponse>
<deletedRecordList>
<deletedRecord>
<deletedDate>2024-03-15T10:30:00</deletedDate>
<record type="salesOrder" internalId="12345"/>
<name>Sales Order #SO123</name>
</deletedRecord>
</deletedRecordList>
</getDeletedResponse>
REST Web Services
In REST web services, you can use SuiteQL queries to return information about deleted records. The basic REST endpoint for using SuiteQL is as follows:
POST https://{accountId}.suitetalk.api.netsuite.com/services/rest/query/v1/suiteql
The following examples show the usage of SuiteQL queries in REST.
Basic Query with User Name Resolution
REQUEST:
{
"q": "SELECT dr.recordid AS internalid, dr.name AS documentnumber, dr.type AS recordtype, dr.deleteddate, dr.deletedby AS deletedby_id, BUILTIN.DF(dr.deletedby) AS deletedby_name, dr.context FROM deletedrecord dr WHERE dr.scriptid = 'salesorder' ORDER BY dr.deleteddate DESC FETCH FIRST 100 ROWS ONLY"
}
RESPONSE:
{
"items": [
{
"internalid": 22522,
"documentnumber": "Sales Order #SO176",
"recordtype": "SALESORDER",
"deleteddate": "9/21/2023",
"deletedby_id": 1112,
"deletedby_name": "Radoslav Bily",
"context": "UIF"
}
],
"hasMore": false,
"totalResults": 58
}
Full Employee JOIN (With Email/Details)
SELECT
dr.recordid AS internalid,
dr.name AS documentnumber,
dr.deleteddate,
dr.deleteddateusertz,
dr.deletedby AS deletedby_id,
e.entityid AS deletedby_loginname,
e.firstname || ' ' || e.lastname AS deletedby_fullname,
e.email AS deletedby_email,
dr.context,
dr.type,
dr.scriptid
FROM
deletedrecord dr
LEFT JOIN employee e ON dr.deletedby = e.id
WHERE
dr.scriptid = 'salesorder'
ORDER BY
dr.deleteddate DESC
FETCH FIRST 100 ROWS ONLY
Multi-transaction Type Query
SELECT
dr.recordid AS internalid,
dr.name AS documentnumber,
dr.type AS recordtype,
dr.scriptid,
dr.deleteddate,
dr.deletedby AS deletedby_id,
BUILTIN.DF(dr.deletedby) AS deletedby_name,
dr.context,
CASE dr.context
WHEN 'UIF' THEN 'User Interface'
WHEN 'WEBSERVICES' THEN 'SOAP Web Services'
WHEN 'RESTWEBSERVICES' THEN 'REST Web Services'
ELSE dr.context
END AS context_description
FROM deletedrecord dr
WHERE dr.scriptid IN ('salesorder', 'invoice', 'purchaseorder', 'vendorbill')
AND dr.deleteddate >= TO_DATE('01/01/2024', 'MM/DD/YYYY')
ORDER BY dr.deleteddate DESC, dr.type
FETCH FIRST 500 ROWS ONLY
Deletions by User Report
SELECT
dr.deletedby AS user_id,
BUILTIN.DF(dr.deletedby) AS user_name,
dr.type AS recordtype,
COUNT(*) AS deletion_count
FROM deletedrecord dr
WHERE dr.deleteddate >= TO_DATE('01/01/2024', 'MM/DD/YYYY')
GROUP BY dr.deletedby, dr.type
ORDER BY deletion_count DESC
FETCH FIRST 50 ROWS ONLY