Is there a way within a Map/Reduce to quickly inac...
# suitescript
n
Is there a way within a Map/Reduce to quickly inactivate or delete all records in custom record? Like without having to loop through a search of each record and delete/inactivate
e
Delete the custom record and recreate it
n
Hmm, could you delete and recreate with same record id and custom field ids? Some of my custom fields on records are list fields
e
With sdf you could, sure.
Well, you could manually as well, but with SDF it would much quicker
just import/download the record definition and then deploy it
n
From within a map/reduce?
e
No. I was suggesting an alternative method. To delete all the records you'll need to use a search in the M/R
n
yeah, that is what I am trying to get around. I have like 20,000 records I need to delete but it is a little slow cause I have to use a search and loop through each one and delete. But need a solution from within MR
e
use the reduce stage and step up your concurrency to the max
👍 1
s
If the point of the map/reduce is the delete custom records, then you should not be looping, the getInput should be returning the records that need to be deleted. Custom records delete pretty quickly
n
@Sandii that is what I am doing but it seems to be taking about 30 minutes to delete 20000-30000 custom records
s
Unless you got userEvents/workflows on those custom records that are triggering when you delete them, it should not take that long.
n
no events or workflows. Pretty basic Custom Record. Pass in search on get input, record.delete in map stage and that is it
s
Well idk, deleting 1k records per minute doesn't sound that slow realistically; I can't really remember if that is normal speed or not
n
fair enough. Wish there was a way to just mass delete them all in suitescript
d
I did something similar not so long back and it pretty quick in an MR, I'm sure it was like 2 mins or so for 20000 rows. Can you post your code? I'll compare with mine tomorrow.
s
I just tested a very simple MR that deleted 28k custom records, and it took an hour to delete them (with concurrency of 1)
n
@Sandii not suprised
@dynamicl i'll take any help. here is my code
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType MapReduceScript
 * @NModuleScope SameAccount
 */

 define([
    'N/record',
    'N/runtime',
    'N/search',
    'N/render',
    'N/email',
    'N/task',
    './moment'],
    /**
    * @param {record} record
    * @param {runtime} runtime
    * @param {search} search
    * @param {render} render
    * @param {email} email
    * @param {task} task
    * @param {moment} moment
    */
    function (record, runtime, search, render, email, task, moment) {

        function getInputData() {
            var customrecord_nco_fam_reporting_combinedSearchObj = search.create({
                type: "customrecord_nco_fam_reporting_combined",
                filters: [],
                columns: []
            });                

            return customrecord_nco_fam_reporting_combinedSearchObj;
        }

        function map(context) {
            record.delete({
                type: 'customrecord_nco_fam_reporting_combined',
                id: searchResults.id * 1
            });
        }

        function reduce(context) {
        }

        function summarize(summary) {

            log.debug('Input Summary: ', JSON.stringify(summary.inputSummary));
            log.debug('Map Summary: ', JSON.stringify(summary.mapSummary));
            log.debug('Reduce Summary: ', JSON.stringify(summary.reduceSummary));

            //Grab Map errors
            summary.mapSummary.errors.iterator().each(function (key, value) {
                log.error(key, 'ERROR String: ' + value);


                return true;
            });
        }

        return {
            getInputData: getInputData,
            map: map,
            reduce: reduce,
            summarize: summarize
        };
    });
s
Copy/paste error?
searchResults
would not be defined in the map stage there
a
How to delete as many record as you need super fast: • Import your custom record definition into an SDF project. • Go to the custom record definition, delete(done, all your records are gone). • Deploy your custom record definition again. Done.
👍 1
n
I can only execute out of a map reduce. No sdf
@alien4u otherwise that sounds good haha
Client will kick off map reduce and so it needs to happen in that process somewhere
b
the idea behind the map/reduce is probably the most sane solution
the code you shared doesnt look right, but its close enough
Ill add that the fun option that you absolutely would not want to maintain involves knowing that
Copy code
record.create({type: 'customrecordtype'});
is possible
n
@battk what’s wrong about it? Would it be faster to do record.submitFields and inactivate instead?
b
Copy code
function map(context) {
  record.delete({
    type: "customrecord_nco_fam_reporting_combined",
    id: searchResults.id * 1,
  });
}
you have a reference error on searchResults
mostly irrelevant, supposedly you ran the script, so what you shared is not what you used
d
As @battk mentioned, that script doesn't work so don't know if we are comparing like for like. I just ran your script by changing searchResults.id*1 to context.key, and deleted 10,000 records in around 1.5 min with a concurrency limit of 2 (which I think everyone should have in an MR). Out of interest, I tried with concurrency limit of 1 as @Sandii did and deleted 10,000 records in 3 min. This is in a dev instance, but I had similar results in a sandbox instance too.
message has been deleted
n
@dynamicl thanks for this help. Even with concurrency 2, it's taking 10 minutes to delete 20,000 records. So, not too bad
👍 1