How to resolve this issue while using map reduce script”TypeError: Cannot read property “OVERWRITE” from undefined”

This article will help you overwrite an existing file with the same name in the file cabinet using SuiteScript 2.0.

1. Create and upload a scheduled script:

  1. Save the below code as .js file:
function execute(scriptContext) {
  1. var fileId = 9505; //file ID
  2. var fileObj = file.load({
  3. id: fileId
  4. });
  5. var fileType = fileObj.fileType;
  6. var fileName = fileObj.name;
  7. var fileContents = fileObj.getContents();
  8. var fileObjSave = file.create({
  9. name: fileName,
  10. fileType: fileType,
  11. contents: fileContents,
  12. folder: 962, //folder ID
  13. });
  14. var fileId = fileObjSave.save();
  15. } 
  16. Go to Customization > Scripting > Scripts > New
  17. Click the “+” icon beside the Script File select field
  18. On the File pop-up window, click Choose File 
  19. Locate your saved file and select it > click the Save 
  20. On the “Upload Script File” page, click Create Script Record 
  21. On the “Script” page, put a script name on the Name field
  22. Click Save 

2. Deploy the script

  1. On the “Script” page, click the Deploy Script 
  2. On the “Script Deployment” page:
  • Enter the title on the Title field
  • Set the Status to Not Scheduled
  1. Click Save.

3. Execute the script

  1. On the “Script Deployment” page, click Edit.
  2. Hover the mouse on the arrow down icon beside the Save button > choose Save and Execute

Leave a comment

Your email address will not be published. Required fields are marked *