Do you see an error in my script? /** * @NApiVers...
# ask-stanley-ai
a
Do you see an error in my script? /** * @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):
Based on the conversations provided, it seems like the error in your script is related to the use of
newRecord.submitFields
. The error message indicates that the
submitFields
function cannot be found in the
newRecord
object. In SuiteScript,
submitFields
is a method of the
N/record
module, not of the
newRecord
object. If you want to use
submitFields
, you should call it directly from the
N/record
module, like this:
Copy code
javascript
record.submitFields({
    type: record.Type.SALES_ORDER,
    id: newRecord.id,
    values: {
        custbody_dyn_mf_printed: true
    }
});
Alternatively, if you want to set a field value on the
newRecord
object, you can use the
setValue
method, like this:
Copy code
javascript
newRecord.setValue({
    fieldId: 'custbody_dyn_mf_printed',
    value: true
});
Please note that if you use
setValue
, you will also need to save the record afterwards using the
save
method. ****** 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.849101663
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835848629
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.835717618
Please provide your feedback on this answer.