Custom Field Processor in code studio


#1

How do I create a custom field processor in code studio to convert field values?


#2

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.

  1. Switch your build environment to the ‘Code Studio’
  2. Select ‘Field Processors’ and click ‘Add new’
  3. Give your field processor a suitable name, in this instance ‘Convert Binary to True or False’
  4. Add the code: return params.input ? “true” : “false”;
    Return%20paramsinput
  5. This simple javascript if then else statement modifies the binary input params.input to either “true” or “false”
  6. After saving this new field processor will be available for selection in your API calls, CSV Imports etc as an available processor.

Preprocessor
Preprocessor.png434x514 15.3 KB

This example replaces the char ‘/’ with ‘.’. Notice this uses a regular expression and therefore some escaping is required.

return params.input.replace(/\//g,".");

Replace%20with

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!