jkabot
03/20/2019, 7:34 PMfunction getScriptFileId(scriptId) {
var results = search.create({
type: 'script',
filters: ['scriptid', 'is', scriptId],
columns: ['scriptfile']
}).run().getRange({ start: 0, end: 1 });
if (results.length === 0) {
return '';
}
return results[0].getValue('scriptfile');
}
function getCurrentScriptFilePath() {
var scriptFileId = getScriptFileId(runtime.getCurrentScript().id);
var scriptFile = file.load({ id: scriptFileId });
return scriptFile.path;
}
function getCurrentScriptFolderPath() {
var scriptFilePath = getCurrentScriptFilePath();
var lastSlash = scriptFilePath.lastIndexOf('/');
return scriptFilePath.substring(0, lastSlash);
}
In use
var scriptFolderPath = getCurrentScriptFolderPath();
var someFile = file.load({ id: scriptFolderPath + "/relative/to/current/script_file.json" });