To open a file in a suitescript we can use file.load() function.
e.g:
var fileObj = file.load({
id: ‘Images/myImageFile.jpg’
});
fileObj.description = ‘my test file’;
var fileId = fileObj.save();
The id field takes the path to the file like shown in the above example or internal of the exact file. See this example:
var fileObj = file.load({
id: 123
});
fileObj.description = ‘my test file’;
var fileId = fileObj.save();
Here 123 is the internal id of the file required.
Similarly we can also use relative path to the file. This can be useful when the path of the file is related to the current script location.
For example if the file to be loaded exists in the same folder. Relative path helps to avoid issues while reusing the same code in sandbox and production accounts or different instances
due to keeping the same internal id. We have to make sure the relative path leads to the file. The code for setting the path is similar to the cmd commands for file traversal.
See example:
var JSONFILE = file.load({ id:”../Monthly UI Navigator/DIAB_CONFIG_MONTHLY_ASSESSMENT_VALUES.json”});
Here the file “DIAB_CONFIG_MONTHLY_ASSESSMENT_VALUES.json” exists in the same folder