Merge Revenue Arrangements Using a Saved Search

The following sample loads a saved search for revenue arrangement records. It obtains the value of the internalid field from each record in the result set, and it adds the values to an array. It calls recognition.create(options) to create a merge task for revenue arrangement records, uses the array as the list of revenue arrangement records to merge, and submits the merge task. The sample also checks the status of the merge task and logs status information.

If you run this sample code in your account, be sure to use a saved search for valid revenue arrangement records in your account.

Note:

This sample script uses the require function so that you can copy it into the SuiteScript Debugger and test it. You must use the define function in an entry point script (the script you attach to a script record and deploy). For more information, see SuiteScript 2.x Script Basics and SuiteScript 2.x Script Types.

          /**
 * @NApiVersion 2.x
 */

require(['N/task/accounting/recognition', 'N/search'], function(recognition, search){
    var mySearch = search.load({
        id: 'customsearch22'
    });

    var elementsList = [];
    mySearch.run().each(function(result) {
        var id = result.getValue({
            name: 'internalid'
        });
        elementsList.push(id);
    });

    var recognitionTask = recognition.create({
        taskType: recognition.TaskType.MERGE_ARRANGEMENTS_TASK
    });

    recognitionTask.arrangements = elementsList;
    recognitionTask.revenueArrangementDate = new Date(2019, 2, 10);

    var taskStatusId = recognitionTask.submit();
    log.debug('taskId = ' + taskStatusId);

    var mergeTaskState = recognition.checkStatus({
        taskId: taskStatusId
    });

    log.debug('Submission ID = ' + mergeTaskState.submissionId);
    log.debug('Resulting Arrangement ID = ' + mergeTaskState.resultingArrangement);
    log.debug('status = ' + mergeTaskState.status);
    log.debug('Error message = ' + mergeTaskState.errorMessage);
}); 

        

General Notices