Does anyone know how I can view the content of a f...
# suitescript
g
Does anyone know how I can view the content of a file from the file cabinet by clicking on a custom body field without it automatically downloading? Trying to create a suitelet however getting an error and then once this works, what type of custom body field should it be and should it be a stored value? /** * @NApiVersion 2.x * @NScriptType Suitelet * @NModuleScope SameAccount */ define(['N/file', 'N/ui/serverWidget'], function(file, serverWidget) { function onRequest(context) { if (context.request.method === 'GET') { var fileId = context.request.parameters.268180; var fileObj = file.load({ id: fileId }); var fileName = fileObj.name; var fileContent = fileObj.getContents(); var fileType = fileObj.fileType; var response = context.response; response.setContentType(fileType, fileName, 'inline'); response.write(fileContent); } } return { onRequest: onRequest }; });
n
I definitely know it’s possible because I use this plug-in called SuiteAdvanced that shows file content preview in a rich text field. https://chrome.google.com/webstore/detail/suiteadvanced-for-netsuit/eambkjlkacecjilgcdmicbpnhkfhdiee
That plug-in does a ton of other things too that are fantastic quality of life changes to netsuite.
I think you have the right idea though. Get the file contents and write them to a text area field
b
g
getting error: Fail to evaluate script: {"type":"error.SuiteScriptModuleLoaderError","name":"UNEXPECTED_ERROR","message":"missing ; before statement (SS_SCRIPT_FOR_METADATA#9)","stack":[]} any idea why?
b
you have a syntax error in there somewhere
g
yep @battk, can you see where the error is?
b
what does the code look like
n
Going out on a limb here but I doubt you have a parameter that has as it's id 268180 var fileId = context.request.parameters.268180;
c
If you do actually have an object with a key of 268180, you'll have to use square brackets. I believe JS will convert a number to a string when you use it as an object key as well. var fileId = context.request.parameters['268180'];