I have been fighting with trying to attach the GL ...
# suitescript
a
I have been fighting with trying to attach the GL impact to my workflow that sends an email anytime an assembly is built. Here is my script and some execution logs. If anyone has any advice I'd be real thankful 🙏🏻
Copy code
/**
 * @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
    };
});
a
are those logs related to this script at all? because they don't appear to be? also, you have said what ACTUALLY happens currently with this script, I'm assuming it doesn't work but is it sending email with nothing attached? is it not sending an email?
a
not sending the email at all. I apologize for the small amount of information I'm very new to this lol. This is where I have the script I'm wondering if thats incorrect because of the fields its looking for are on a different transaction page?
image.png
also the logs I attached are the only things popping up in the time frame I'm completing a build
a
... yeah that is not where the JS file needs to go 🙂
that's for the actual file attachment on the email
so you need a script record, and a script deployment record to the transaction type that this workflow triggers on... do you have all that already?
a
Copy code
/**
 * @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();

            // Save the File ID to a custom field on the transaction
            record.submitFields({
                type: 'transaction',
                id: assemblyId,
                values: {
                    custbody_gl_impact_pdf: fileId // Replace with your custom field ID
                }
            });

            log.audit('Success', 'GL Impact PDF generated and saved 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
    };
});
a
... this is script file
crying sunglasses 1
a script record is a netsuite record
a script deployment is a child record of a script and governs when and how that script executes
a
than no sir I do not. I am letting chatgpt take the wheel and trying to follow it and work with the errors I'm seeing, which as you can see is not working out for me lol
a
image.png
that will prompt you for a file to be uploaded
a
yes and than I upload the above I just pasted correct
a
correct
a
well that script is now asking for a custom plug-in type which I have no options when I click the drop down
a
custom plugins is optional, just dont put anything in there
a
regardless of red *?
a
idk what your screen looks like, on THIS page?
1
a
yep that is it. I have it saved now and changed my File cabinet folder ID to what I believe is correct
a
what I believe is correct
this does not fill me with confidence 😄
10 4 1
a
lets just say im glad I got a sandbox account lol
before I go past this page I don't need any of the other fields completed? Parameters, unhandled, deployments?
so the script should just run with the workflow and attach? No need to actually add it in the workflow?
a
you will need a deployment on the assembly
but you dont need to do that before saving the script record
a
deploying here? or is this where the "child record" comes in?
a
yeah that's a deployment
yeah the deployment is effectively a child record of the script record
a
so when I think child record I think its going to be something other than the actual script? or am I totally off lol
common/record/edittextmediaitem.nl?id=126326&e=T&l=T&target when I hit preview on my script I used the 126326 for my folder:
a
sorry I'm in meetings now 😞
🙏 1
a
no problem at all! I appreciate you going back and forth for a bit lol