Sometimes you need to transform a field by removing formatting characters and just keeping the value. For example, If you need only numbers to be exported from Flatfile but the user uploads fields with dollar signs, periods, and commas, you can remove those characters with a Data Hook like this.
For more information about Data Hooks for Portal 3.0 and Workspaces, please visit our guide.
module.exports = async ({ recordBatch, session, logger }) => { // create an array of all the fields you need cleaned const currencyFields = ["compensationAmount", "salary", "hourlyRate"]; recordBatch.records.forEach((record) => { currencyFields.forEach((fieldName) => { const currField = record.get(fieldName); if (currField) { //use regex to find all '$' '.' and ',' and remove them record.set(fieldName, currField.replace(/\$\.,/g, "")); record.addInfo(fieldName, "Special characters removed"); } }); }); };
Comments
0 comments
Please sign in to leave a comment.