In case there is a need to rename a folder name on File Cabinet due to changes in the directory where the script generated documents are being saved for example. It is possible to use SuiteScript to change the folder name in the File Cabinet.
The following example uses the N/record Module to load the folder record proprieties. The name of the Folder is a mandatory field
/**
*@NApiVersion 2.0
*@NScriptType Suitelet
*/
define(['N/record'], function (record) {
/**
* @param {SuiteletContext.onRequest} context
*/
function changeFolderName(context) {
try {
var renameFolder = record.load({
type: record.Type.FOLDER,
id: -16,
isDynamic: false,
defaultValues: null
});
if (renameFolder){
renameFolder.setValue({
fieldId: 'name',
value: 'Changed_Name',
ignoreFieldChange: true
});
renameFolder.save();
}
}
catch (error) {
log.debug({title: 'Catch, Error > ', details: error });
}
}
return {onRequest: changeFolderName};
});