Adam Weaver
11/19/2024, 3:22 PM/**
* @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
};
});
Anthony OConnor
11/19/2024, 3:43 PMAdam Weaver
11/19/2024, 3:46 PMAdam Weaver
11/19/2024, 3:47 PMAdam Weaver
11/19/2024, 3:48 PMAnthony OConnor
11/19/2024, 3:49 PMAnthony OConnor
11/19/2024, 3:49 PMAnthony OConnor
11/19/2024, 3:50 PMAdam Weaver
11/19/2024, 3:51 PM/**
* @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
};
});
Anthony OConnor
11/19/2024, 3:53 PMAnthony OConnor
11/19/2024, 3:53 PMAnthony OConnor
11/19/2024, 3:53 PMAdam Weaver
11/19/2024, 3:54 PMAnthony OConnor
11/19/2024, 3:54 PMAnthony OConnor
11/19/2024, 3:55 PMAdam Weaver
11/19/2024, 3:55 PMAnthony OConnor
11/19/2024, 3:55 PMAdam Weaver
11/19/2024, 3:56 PMAnthony OConnor
11/19/2024, 3:58 PMAdam Weaver
11/19/2024, 3:59 PMAnthony OConnor
11/19/2024, 4:00 PMAdam Weaver
11/19/2024, 4:00 PMAnthony OConnor
11/19/2024, 4:02 PMwhat I believe is correctthis does not fill me with confidence 😄
Adam Weaver
11/19/2024, 4:03 PMAdam Weaver
11/19/2024, 4:05 PMAdam Weaver
11/19/2024, 4:09 PMAnthony OConnor
11/19/2024, 4:10 PMAnthony OConnor
11/19/2024, 4:10 PMAdam Weaver
11/19/2024, 4:13 PMAnthony OConnor
11/19/2024, 4:22 PMAnthony OConnor
11/19/2024, 4:22 PMAdam Weaver
11/19/2024, 4:25 PMAdam Weaver
11/19/2024, 4:27 PMAnthony OConnor
11/19/2024, 4:32 PMAdam Weaver
11/19/2024, 4:34 PM