0
votes

I could get deleted records from Netsuite using below script. But I could not get id.

var customSearch = search.create({
     type: "deletedrecord",
     columns: ["context", "deletedby", "deleteddate", "externalid", "name"],
     filters: [
         ["recordtype", "is", "customer"]
     ]
});
var resultSet = customSearch.run().getRange({
    start: 0,
    end: 5
});

How can I get unique id of deleted records from Netsuite using Suitescript 2.0?

2
These days it's easiest to create the saved search in NetSuite and then use a browser plugin to convert it to code.Brian
Looks like it isn't available through saved searches, odd because it is accessible through SuiteTalk SOAP calls.Brian

2 Answers

0
votes

That information isn't available on an internal search.

You can get that a few different ways though.

It's available in SuiteTalk using the getDeleted operation

It's available via an external database query using SuiteConnect (ODBC, JDBC or ADO.net)

If you can start from now an easy hack is as follows:

create an After Submit User Event script that runs on record creation. If the record doesn't have an external id push the namespaced netsuite internal id into that field. I've found it's generally a good idea to prefix your external ids with the system of origin.

Now you can derive your internal ids from the external id. This doesn't help if you also have actual externalids but may suit your use case.

You can also fairly easily roll your own and create an after submit user event script that populates a custom record with the type and internalid of the deleted record. It's generally the way I go. Particularly if you are driving other suitescripts or workflows in your Netsuite account from the deletion data

Finally, though I haven't done this in years, it's quite possible to run a SuiteTalk query from SuiteScript. You just have to save the credentials (not in the clear) and construct the appropriate SOAP message.

0
votes

Suite Answer Id: 69458 suggests the following will work:

var deletedRecords = search.create({
    type: "deletedrecord",
    filters:[
        ["deleteddate","within","today"]
    ],
    columns:[
        search.createColumn({name: "externalid"}),
        search.createColumn({name: "deleteddate"}),
        search.createColumn({name: "deletedby"}),
        search.createColumn({name: "context"}),
        search.createColumn({name: "name"})
    ]
});

var searchResultCount = deletedRecords.runPaged().count;
log.debug("deletedRecords result count",searchResultCount);

deletedRecords.run().each(function(result){
    // .run().each has a limit of 4,000 results
    return true;
});

Per the 2020.2 Records Browser only "externalid" is available though. Sometimes the external and internal ids are the same in my system; not sure about your specific set up for NetSuite.