Skip to content

Instantly share code, notes, and snippets.

@abacijson
Last active November 23, 2019 01:25
Show Gist options
  • Select an option

  • Save abacijson/1484d5fc2b0c588cfede83a2f6dd9f1e to your computer and use it in GitHub Desktop.

Select an option

Save abacijson/1484d5fc2b0c588cfede83a2f6dd9f1e to your computer and use it in GitHub Desktop.
automergeSs2_0sample.js
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define(['N/task/accounting/recognition', 'N/search'],
function(recognition, search) {
/**
* Definition of the Scheduled script trigger point.
*
* @param {Object} scriptContext
* @param {string} scriptContext.type - The context in which the script is executed. It is one of the values from the scriptContext.InvocationType enum.
* @Since 2015.2
*/
function execute(scriptContext) {
var currentScript = runtime.getCurrentScript();
// get the Saved Search ID from the script parameter set by the user
var searchIdParam = currentScript.getParameter({
name: 'custscript_my_rev_arr_search'
});
// load search and get the Internal ID of each Revenue Arrangement
var revArrSearch = search.load({
id: searchIdParam
});
var elementsList = [];
revArrSearch.run().each(function(result){
var resultId = result.getValue({
name: 'internalid'
});
elementsList.push(resultId);
});
// Create a new Revenue Arranagement merge task using the new module's API
var mergeTask = recognition.create({
taskType: recognition.TaskType.MERGE_ARRANGEMENTS_TASK
});
// Pass the list of IDs to be merged to the Task object
mergeTask.arrangements = elementsList;
// Set the merge date of the task using a JavaScript Date object
mergeTask.revenueArrangementDate = new Date(2019, 3, 1);
// Indicates whether the revenue arrangements are merged prospectively (true) or retrospectively (false)
mergeTask.mergeResidualRevenueAmounts = true;
// Indicates whether to recalculate the fair value on residual elements when revenue arrangements are prospectively merged.
mergeTask.recalculateResidualFairValue = true;
// returns the newly created task ID
var mergeTaskId = mergeTask.submit();
// ability to check the status of the task and run logic accordingly
var mergeTaskState = recognition.checkStatus({
taskId: mergeTaskId
});
// log any potentially helpful information
log.debug('Submission ID: ', mergeTaskState.submissionId);
log.debug('Resulting Arrangement ID: ', mergeTaskState.resultingArrangement);
log.debug('status: ', mergeTaskState.status);
log.debug('Error message: ', mergeTaskState.errorMessage);
}
return {
execute: execute
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment