I'm trying to use a relative path with `file.load`...
# suitescript
d
I'm trying to use a relative path with
file.load
in a user event script. However I keep getting
RCRD_DSNT_EXIST
. Am I doing this wrong?
j
If you ever have a real need to load by a relative path, I have had success with this method.
Copy code
function scriptFolderPath() {
    var script = runtime.getCurrentScript();
    var results = search.create({
        type: 'script',
        filters: ['scriptid', 'is', script.id],
        columns: ['scriptfile']
    }).run().getRange({ start: 0, end: 1 });
    if (results.length === 0) {
        throw new Error('Failed to look up script file.');
    }
    var scriptFileId = results[0].getValue('scriptfile');
    var scriptFilePath = file.load({ id: scriptFileId }).path;
    var lastSlash = scriptFilePath.lastIndexOf('/');
    return scriptFilePath.substring(0, lastSlash);
}
// ...
var relativeFile = file.load({ id: scriptFolderPath() + '/path/to/relative_file.html' }).getContents();