Export Saved Search to FTP folder
# ask-stanley-ai
m
Export Saved Search to FTP folder
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you can export a Saved Search to an FTP folder using SuiteScript by following these steps: 1. Process the Saved Search and write the results to a CSV file using a script. 2. Use the
N/sftp
module to upload the CSV file to an SFTP server. Here is a sample code snippet that demonstrates this process:
Copy code
javascript
const executeExportIntegration = (record) => {
    let searchId = record.getValue('custrecord_mvc_saved_search');
    let fileName = record.getValue('custrecord_mvc_file_name');
    let directory = record.getValue('custrecord_mvc_ftp_folder');

    if(fileName === '') {
        fileName = searchId;
    }

    const searchToExport = search.load({id: searchId}).run().getRange({
        start: 0,
        end: 1000
    });

    let csvData = _convertSearchToCsv(searchToExport);

    let fileObj = file.create({
        name: fileName + '.csv',
        fileType: file.Type.PLAINTEXT,
        contents: csvData
    });

    let connection = _connectionSFTP(record);

    let objConnection = connection.list({
        path: directory
    });

    log.debug('Current Folder', objConnection);

    connection.upload({
        file: fileObj,
        filename: 'af.txt',
        replaceExisting: true
    });
}
Please note that this code assumes that you have functions
_convertSearchToCsv
and
_connectionSFTP
defined elsewhere in your script. The
_convertSearchToCsv
function should convert the Saved Search results into CSV format, and the
_connectionSFTP
function should establish an SFTP connection. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.856191337
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.85195291
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.837210119
Please provide your feedback on this answer.