This topic contains 4 replies, has 0 voices, and was last updated by ironside 8 years, 1 month ago.
-
AuthorPosts
-
September 28, 2016 at 7:27 am #1767
jonathan@velaro.comI’m trying to create a file with code such as the following, but when it gets to the file.create it throws an exception ‘Unexpected error’. Anyone seen this before?
Code:
/**
*@NApiVersion 2.x
*@NScriptType Restlet
*/
define([‘N/file’], function (file) {function post(){
var fileRequest = { name: ‘test’ + ‘.txt’, fileType: file.Type.PLAINTEXT, contents: ‘test’, description: ‘f’, folder: 165 };
try {
var resultingFile = file.create(fileRequest);
}
catch (ex) { debugger; }
var fileId = resultingFile.save();
}
});
This is a cached copy. Click here to see the original post. -
September 28, 2016 at 7:50 am #1768
JacksonPI’ve created files before as a csv, It could be that you need to set the folder after creating the object
Code:
var fileObj = file.create({
name: fname,
fileType: file.Type.CSV,
contents: resultSet.join(‘n’)
});fileObj.folder = 4724267;
fileObj.save()
jonathan@velaro.com replied on 09/28/2016, 07:55 AM: Thanks i’ll try that. The documentation made it seem that the folder could be set at the time of creation.
-
September 28, 2016 at 7:51 am #1769
darrenhillconsultingWhy are you saving inside the catch? It’ll never be reached (unless the file/create throw an exception.
Try it like this
Code:
/** *@NApiVersion 2.x *@NScriptType Restlet */
define([‘N/file’], function (file) {
var fileRequest = { name: ‘test’ + ‘.txt’, fileType: file.Type.PLAINTEXT, contents: ‘test’, description: ‘f’, folder: 165 };
try {
var resultingFile = file.create(fileRequest);
var fileId = resultingFile.save();
} catch (ex) {
debugger;
} //TODO: Only put code in here to handle the exception/error.
});
jonathan@velaro.com replied on 09/28/2016, 07:57 AM: Save isn’t in the catch, only thing in the catch is debugger; Error is occurring at file.create, not in the save.
-
September 28, 2016 at 8:04 am #1770
darrenhillconsultingJonathan,
The bigger issue is, your code has no valid entry point
jonathan@velaro.com replied on 09/28/2016, 08:06 AM: Ah, guess my example wasn’t 100% correct, i have it wrapped in an entry point function name ‘post’. I’ll update my sample.
-
September 28, 2016 at 9:23 pm #1771
ironsideYou need to define the entrypoints – which means you need to return something from your function(file)…
-
AuthorPosts
You must be logged in to reply to this topic.