```i have a .msg file. In NetSuite, below script i...
# ask-stanley-ai
v
Copy code
i have a .msg file. In NetSuite, below script is giving error when fileObj is of type .msg which is MISCBINARY in NetSuite. 

var renderer = render.create();
            renderer.templateContent = fileObj.getContents();
			renderer.isOnline = true; 
            newFile = renderer.renderAsPdf();

			var newFile = file.create({
                name: fileObj.name.replace('.','_') + '-' + fileId + '.pdf',
                fileType: file.Type.PDF,
                contents: newFile.getContents(),
                folder: folderId,
                isOnline: true
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems like the issue you're facing is related to the handling of binary files in NetSuite. When you're dealing with binary files such as .msg or .pdf, NetSuite treats them as base64 strings. In your script, you're trying to get the contents of the .msg file using
fileObj.getContents()
, which returns a base64 encoded string. Then, you're trying to use this base64 string as the template content for the renderer, which is likely causing the error. The
render.create()
method is used to create a PDF or HTML document using a FreeMarker template. The
templateContent
property expects a FreeMarker template, not a base64 string. If you're trying to convert the .msg file to a PDF, you might need to use a different approach, as NetSuite's rendering engine might not support this directly. You might need to convert the .msg file to a format that the rendering engine can handle (like HTML or XML), and then use that as the template content. Here's a simplified example of how you might use the rendering engine:
Copy code
javascript
var renderer = render.create();
renderer.templateContent = '<#-- This is a FreeMarker template -->';
renderer.addRecord('record', record.load({
    type: record.Type.INVOICE,
    id: invId
}));
var newFile = renderer.renderAsPdf();
In this example,
templateContent
is a FreeMarker template, not a base64 string. Remember, this is a simplified example and might not work for your specific use case. You'll need to adjust it based on your requirements. ****** 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.874095619
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.862759769
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.843009114
Please provide your feedback on this answer.