RE: Suite script to import and run csv file

Hi Expert,In order to create a journal entry we need to populate a csv file with required fields and run in the UI.Can we write a suitte script to read the csv file and run that csv file to generate a journal entry .Could you please help out ?

AHarshini Rookie Asked on June 30, 2022 in SuiteScript.
Add Comment
4 Answers

Ciao AHarshini

you can use this code:

  • SuiteScripts / ASGCutAssembly.csv is the name of the excel file and the path in the cabint
  • custimport_asg_mc_import_script_test is the name of the created excel import

 

mauro

/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
* @NModuleScope SameAccount
*/
define([‘N/task’, ‘N/file’],

function(task,file) {

/**
* 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) {

// CARICA E LANCIA UN IMPORT CSV RECORD
var scriptTask = task.create({ taskType: task.TaskType.CSV_IMPORT });
scriptTask.mappingId = “custimport_asg_mc_import_script_test”;
var f = file.load(“SuiteScripts/ASGCutAssembly.csv”);
scriptTask.importFile = f;
var csvImportTaskId = scriptTask.submit();
// CARICA E LANCIA UN IMPORT CSV RECORD

// CANCELLA IL FILE
var fileId = f.save();
file.delete({
id: fileId
});
// file.delete({id: “SuiteScripts/ASGCutAssembly.csv”});
// CANCELLA IL FILE

}

return {
execute: execute
};

});

Rookie Answered on July 13, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.