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 ?

Rookie Asked on June 30, 2022 in SuiteScript.
Add Comment
4 Answer(s)

What I would do is create a Suitelet script with a field of type FILE, and a button.

When the user presses the button it sends POST to the same suitelet script.

Have the POST request parse the CSV file with

'N/file'
or what I use is Papa Parse (you can load into the script like this
'../modules/papaparse.min'
).

Once you have parsed the file and loaded into a Javascript Object then use it to create the record.

You can redirect the user to created record after it finishes saving.

Rookie Answered on June 30, 2022.

Hi marvinroman,
I was not clear i think.let me re Iterate
I have created a csv file which has subsidiary,account and all the required fields to generate a journal entry.Now, generally in the ui ,we go to yhe saved csv file upload the csv file and save and run.
Now i want to automate this for example the csv file which has to be uploaded will be placed in file cabinet and netsuite should know that it is a csv file which has to be uploaded and journal entry should be created.can i automate this process using suite script?

on July 1, 2022.
Add Comment

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

Yes, this can be automated with Suite Script. That being said, how much value does this really add if the user still needs to manually add the file to the appropriate file cabinet folder vs using a saved CSV import template? Fewer clicks perhaps, but you are talking about 1-2 seconds difference.

If you are planning to automate the files being loaded into the file cabinet for CSV import processing i.e. a no touch process, then I would see value in automating the process via Suite Script.

I hope this helps!

Sonny

Beginner Answered on July 19, 2022.
Add Comment

hi Sonny,
in my case, for my work, I created a script with sutetalk to automatically import the file into the cabinet
in this way I have made the process completely automated

I hope it can be of help

code

string filename = “PeopleExpress.csv”;
byte[] fileContent = System.IO.File.ReadAllBytes(path);

public static void uploadfile(NSClient ns, string NetsuiteCartella, byte[] fileContent, string filename)
// UPLOAD file cabinet
{
ns.SetPreferences();
FolderSearch fldSearch = new FolderSearch();
FolderSearchBasic fldSrearchBasic = new FolderSearchBasic();
SearchStringField searchFolder = null;
//Name of the folder that we want to search
string searchValue = NetsuiteCartella;
//Filtering by the folder name
searchFolder = new SearchStringField();
searchFolder.@operator = SearchStringFieldOperator.@is;
//Search operator
searchFolder.operatorSpecified = true;
searchFolder.searchValue = searchValue;
//searchValue is name of the folder “Demo”
fldSrearchBasic.name = searchFolder;
fldSearch.basic = fldSrearchBasic;
// Search by isActive field which is a boolean
SearchBooleanField isActive = new SearchBooleanField();
isActive.searchValue = true;
isActive.searchValueSpecified = true;
// Invoke search() web services operation
SearchResult response = Client.Service.search(fldSearch);
//Now stroring the search result in an array
Record[] arrRecord = (Record[])response.recordList;
// Process response
if (response.status.isSuccess)
{
Console.WriteLine(“internalId : {0}”, “search is successful”);
Folder fldr = (Folder)arrRecord[0];
//Getting a specific folder from the search
string fldrId = fldr.internalId;
//Fetching the required folder’s internal ID
RecordRef refId = new RecordRef();
refId.internalId = fldrId;
//Storing the folder id
//File object created to get all the file information
File objFile = new File();
objFile.name = filename; //setting the file name
objFile.folder = refId; //setting the folder information
objFile.content = fileContent; //settig the file content
ns.SetPreferences();
WriteResponse writeResponse = Client.Service.add(objFile);
}
else
{
Console.WriteLine(“internalId : {0}”, “search not found”);
return;
}
}

 

ciao

mauro

Rookie Answered on July 19, 2022.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor