Search code examples
netsuitesuitescriptsuitescript2.0

How to check whether the folder name exists in file cabinet using suitescript 2.0


I am creating folder to push monthly invoices through suitescript 2.0. I want to validate whether the current month's folder already created/exists, so that I can skip the folder creation code if it exists. As of now I am getting folder exists error


Solution

  • To verify if folder already exists in File Cabinet, you can create a search on recordType: folder.

    eg.

    search.create({
      type: 'folder',
      filters: [
        ['name', 'is', FOLDER_NAME], 
        'and', 
        ['parent', 'anyof', [PARENT_FOLDER_ID]]
      ]
    }).run().getRange({ start: 0, end: 1 });
    

    You can check NetSuite's Record Browser to get all valid search-filters and columns .