2-4 Modify NiFi Attributes with Custom Scripting
This example introduces the ExecuteScript processor and demonstrates how to add an attribute with a Groovy script. In our example scenario, we extract an email property from a JSON file, then run a script that calculates a SHA-1 hash of the email attribute and stores that back in a different attribute which is used to build the MarkLogic URI.
- email-hash.groovy
- Download Template
- Processors:
- GetFile – reads files from a watched directory
- Properties
- Input Directory: /some/path
- Properties
- EvaluateJsonPath - Store values from JSON in FlowFile properties
- Properties
- Destination: flowfile-attribute
- email: $.email (custom property)
- Settings
- Check "failure" and "unmatched" under "Automatically Terminate Relationships".
- Properties
- ExecuteScript
- Properties
- Script Engine: Groovy
- Script Body: (paste contents of email-hash.groovy from above)
- Settings
- Check "failure" under "Automatically Terminate Relationships".
- Properties
- UpdateAttribute
- Properties
- marklogic.uri: /people/${emailHash}.json (custom property)
- Properties
- InvokeHTTP – HTTP PUT to MarkLogic REST API /LATEST/documents
- Properties
- HTTP Method: PUT
- Remote URL: http://localhost:8000/LATEST/documents?uri=${marklogic.uri}.json
- Basic Authentication Username: youruser
- Basic Authentication Password: yourpassword
- Settings
- Check all five checkboxes under "Automatically Terminate Relationships"
- Properties
- GetFile – reads files from a watched directory
![](../images/24-001 Custom Scripting whole flow.png)
- More ExecuteScript examples: