The script used to create the CSV file using JSON data and save the file in the filecabinet folder.

The following function can be used to create the CSV file using JSON data and save the file in the file cabinet folder.

            /**
            * @description creates the csv file using JSON data. The papaparse library used to unparse the JSON data for the CSV file creation
            * @param errorFileData JSON dataa
            * @param folderId id of filecabinet folder
            * @param fileName filename
            * @returns {*}
            */
            function createFiles(errorFileData, folderId, fileName) {
                try {
                    let finalDataToParse = papa.unparse(errorFileData);
                    log.debug('finalDataToParse', finalDataToParse);
                    let newFile = file.create({
                        name: fileName,
                        fileType: file.Type.CSV,
                        folder: folderId,
                        contents: finalDataToParse,
                    });
                    newFile.isOnline = true;
                    let fileId = newFile.save();
                    log.debug('fileid', fileId);
                    return fileId;
                }
                catch (e) {
                    log.error('error @ createFiles', e);
                }
            }

        }

Leave a comment

Your email address will not be published. Required fields are marked *