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. In this example the Internal ID corresponds to the SuiteBundles folder which is default to NetSuite.
- Navigate to Customization > Scripting > Scripts > New
- Click the (+) icon to upload the Script File with the sample code below
- Click Create Script Record
- Basic Information:
- Name: Enter Change Folder Name
- ID:Enter the Script ID
- Click Save & Deploy
- Basic Information:
- Title: Enter Change Folder Name
- ID: Enter Deployment ID
- Status:Select Released
- Log Level:Select Debug
- Execute As Role:Select Administrator
- Click Save
/**
*@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
};
});
Note: The values used on this solution are account specific and the same should be adapted to the account where the solution is tested.