Help

Trim& substitute using script

Topic Labels: Automations
1729 4
cancel
Showing results for 
Search instead for 
Did you mean: 
Jessica_Shin
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi,
here I have a column shows tracking number from multiple shipping carriers.
some are something like ‘6495-4289-3463’(number+‘-’) or some are like ‘343918 ai19’ (text+number+space).
I would like to turn these into only number and text without any ‘-’ or space.

It seems like I can use trim and substitute for formula, however, I don’t want to create extra column for it. Therefore, I want to use script using automation when context is filled.
what would be the script l can use?

4 Replies 4

Hi,
use

const txt=input.config().text.split(' ').join('').split('-').join('')
output.set('txt',txt)

use output of this step to update record

Thank you for the reply Alexey,
Following your script, I should replace text as {tracking number} and ‘txt’ as ‘{tracking number}’?
If so, it doesn’t seem to work.
I don’t know about coding so much.
thanks again in advanced.

You mentioned automation. So, you have to input your text into script step and then use output for next step. Like this:
image

image
image

‘text’ and ‘txt’ are variable names, you can choose it on your own.
in my example, line breaks also present, that’s why output looks like still contain spaces

Usually, scripts in airtable following this scenario:

  1. you input some data (value or array)
  2. data being transformed, sometimes according to other table
  3. you get output data (array to create or update records, or value)

automation can help with better understanding of process, you may construct steps 1 and 3 in automation gui, without code. despite you can’t update several records in a single update action, you can ‘mark’ them if they linked to other table and setup other automation to process all marked.

in your case, script just transforms input value ‘text’ to output value ‘txt’

Jessica_Shin
5 - Automation Enthusiast
5 - Automation Enthusiast

Thank you so much!
Didn’t realized that I have to define the textInput on the leftside of the edit script window.

It may help others who have trouble like me.
Hope this helps:
const textOutPut=input.config().textInput.split(’ ‘).join(’‘).split(’-‘).join(’')
output.set(‘textOutPut’,textOutPut)