Remove Commas From Export Fields
When importing data into another system, you may need to remove commas from text fields to make the file compatible. The JavaScript configuration below allows you to strip commas, leaving you with a usable export file.
Setting Up the Export
To complete this configuration, you'll need to add a Calculated Field to a Tabular/Spreadsheet Export. You can do this while configuring your Export by dragging a Calculated Field into the Columns to export.
After dropping in the Calculated Field, use the JavaScript Expressions option by dropping the code listed below into the Expression field. Then, update the code to indicate which field you are exporting.
JavaScript Code
After following the steps above, use the following code in your JavaScript Expression:
{ /* * * * * * * * * * * * * * * USER INPUT SECTION * * * * * * * * * * * * * * */ // use this field to designate the key of the desired form let form = 'add_your_form_key_here'; // use this field to add the key of the desired field let field = 'add_your_field_key_here'; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * DO NOT EDIT BELOW * * * NOTE: This function takes two inputs and return a single question response from the * Outcomes Application Data Object. This response is modified to remove any commas * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ function removeCommas(formID, fieldID) { if ((forms) && (forms[formID]) && (forms[formID][fieldID])) { let string = forms[formID][fieldID]; let noCommas = string.replace(/,/g, ""); return noCommas; } else { return ""; } } return removeCommas(form, field); }
Modify the Code
Once you've added this code into your JavaScript expression, you'll need to modify it in the following ways:
- Indicate which field you want to strip the commas from. Each form in the software has a key associated with it. Each field within each form also has a key. Find the key of the form you want to use, and update the let form = line, replacing add_your_form_key_here with that key.
- Find the key for the specific field you want to export. Use that to replace add_your_field_key_here on the let field = line.
- Using the sample screenshot above, if you wanted to export the Recommend decision field and strip the special commas from it, the top of the Expression field would contain the following lines:
let form = 'committee_review'; let field = 'committee_decision';
- After modifying the JavaScript Expression, click Update. Continue adding fields as needed, and then run your Export.
- If there are other fields you need to remove commas from, continue adding Calculated Fields and repeat steps 1-4 as described above. Then run your export.