How do I create a custom field processor in code studio to convert field values?
Hi Ian, this is a really useful skill and thankfully it is quite simple.
The example below converts a Mats Binary into the string values “true” or “false”. This can be useful in preparing field data for use in a restful API. I’ll also include the code for exchanging one character for another.
- Switch your build environment to the ‘Code Studio’
- Select ‘Field Processors’ and click ‘Add new’
- Give your field processor a suitable name, in this instance ‘Convert Binary to True or False’
- Add the code: return params.input ? “true” : “false”;
- After saving this new field processor will be available for selection in your API calls, CSV Imports etc as an available processor.
This example replaces the char ‘/’ with ‘.’. Notice this uses a regular expression and therefore some escaping is required.
Please share if you do create any code studio items you believe may be of use to others.
If you get stuck on your particular use case, please let us know and we’d be happy to help!