can you re-write this script correctly /** * @NAp...
# ask-stanley-ai
a
can you re-write this script correctly /** * @NApiVersion 2.x * @NScriptType WorkflowActionScript */ define(['N/render', 'N/file', 'N/record'], function (render, file, record) { function onAction(context) { try { // Get the current transaction ID var assemblyId = context.newRecord.id; // Generate the GL Impact PDF var pdfFile = render.transaction({ entityId: assemblyId, printMode: render.PrintMode.PDF }); // Save the file in the File Cabinet var savedFile = file.create({ name: 'GL_Impact_' + assemblyId + '.pdf', fileType: file.Type.PDF, contents: pdfFile.getContents(), folder: 12345 // Replace with your File Cabinet folder ID }); var fileId = savedFile.save(); // Attach the file to the transaction record record.attach({ record: { type: 'file', id: fileId }, to: { type: 'transaction', id: assemblyId } }); log.audit('Success', 'GL Impact PDF generated and attached successfully.'); } catch (error) { log.error('Error Generating GL Impact PDF', error.message); throw error; // Re-throw the error to inform the workflow of the failure } } return { onAction: onAction }; });
c
AI generated answer (using internal Slack threads):
The script you provided is a Workflow Action Script in SuiteScript 2.0. It generates a PDF of the GL Impact of a transaction, saves it in the File Cabinet, and attaches it to the transaction record. Here is the corrected version of the script:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType WorkflowActionScript
 */
define(['N/render', 'N/file', 'N/record'], function (render, file, record) {
    function onAction(context) {
        try {
            // Get the current transaction ID
            var assemblyId = context.newRecord.id;

            // Generate the GL Impact PDF
            var pdfFile = render.transaction({
                entityId: assemblyId,
                printMode: render.PrintMode.PDF
            });

            // Save the file in the File Cabinet
            var savedFile = file.create({
                name: 'GL_Impact_' + assemblyId + '.pdf',
                fileType: file.Type.PDF,
                contents: pdfFile.getContents(),
                folder: 12345 // Replace with your File Cabinet folder ID
            });
            var fileId = savedFile.save();

            // Attach the file to the transaction record
            record.attach({
                record: {
                    type: record.Type.FILE,
                    id: fileId
                },
                to: {
                    type: record.Type.TRANSACTION,
                    id: assemblyId
                }
            });

            log.audit('Success', 'GL Impact PDF generated and attached successfully.');

        } catch (error) {
            log.error('Error Generating GL Impact PDF', error.message);
            throw error; // Re-throw the error to inform the workflow of the failure
        }
    }

    return {
        onAction: onAction
    };
});
****** 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.847320318
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.845299244
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842111349
Please provide your feedback on this answer.
Thank you for your feedback