RecordsFilter - Bad Words Filter.


Table of Contents



Overview

The BadWords filter scans the object's fields listed in the detectFields for unwanted words, then can output the matched words to the console or even modify the source field value to highlight these words, then upload the modified value to the target (or write to the CSV file).

The BadGet.ords filter can be very useful, for example, for GDPR requirements.

This filter leverages the RecordsFilter Core Add-On Module features.

This filter was implemented thanks to the contribution of the author of the amazing tool SFDX Hardis.

BadWords Filter Setup

Below is the example configuration for the BadWords filter:

{
   "objects": [
     {
         "operation": "Upsert",
         "externalId": "LastName",
         "query": "SELECT LastName, Description FROM Contact",
         "filterRecordsAddons": [
            {
                "module": "core:RecordsFilter", // Always must be `BadWords` (the type of the filter).
                "args" : {
                    "filterType": "BadWords",
                    "settings" : {
                        "badwordsFile": "./badwords.json",
                        "detectFields": [
                            "Description"
                        ],
                        "highlightWords" : true,
                        "outputMatches": true
                    }
                }
            }
         ]
     }
   ]
}

And the specification of filter settings is:

badwordsFile (String)

Optional, Default: "badwords.json". The path to the json file where you can list bad words you want to detect. In the default case, the file should be placed in the same directory as the export.json.

detectFields (String[])

Mandatory. Sets the list of object's fields to scan for bad words.

highlightWords (Boolean)

Optional, Default: false. Set to true to modify the input record by highlighting the matched bad words with stars. For example, if you defined the bad word list as ["bad", "word"] and the input record value is "good word bad word", it will be replaced with "good word ***bad*** ***word***".

outputMatches (Boolean)

Optional, Default: false. Set to true to output matched bad words to the Console.

Additional Notes

  • The JSON file is allowed to be placed in any location on the disk. You can name it differently, but the default name when you omit this property is badwords.json. Populate this property with the absolute path (or the path relative to the export.json).

  • If badwords.json does not exist or has an incorrect format, the module will throw an error.

  • The records are getting filtered only if the desired field is included in the object's query string and the field is of an updatable type.

  • Below is the required format of the badwords.json file. List all bad words you want to detect in the badwords array:

    {
      "badwords": [
        "bad",
        "word"
      ]
    }
    
Last updated on 11th May 2024