Script to move text to links

Viewing 1 reply thread
  • Author
    Posts
  • February 23, 2020 at 4:09 PM #39632

    JBW
    Participant

    Hey there. I’m trying to move from airtable to tap forms.

    I can (and have) downloaded the tables from airtable to csv files. I can import these csv files as forms into tap forms. However, I cannot seem to link certain fields to other forms during the import. After I’ve toyed around a bit, I think I understand why I couldn’t do that. But maybe I’m missing something.

    So I tried to build a script that would take an existing text field, and move it over to an already “linked to” form. But I’m not a script writer.

    I need some help.

    I have a form called “classes” with a field called “players” that has comma delimited names in it as text. I would like to have a script that goes to each “players” field, grab each name, and add them to the “linked to” field called “players-linked”.

    I have another form called “players” that has each individual as a record (first name, last name, etc.).

    I can code a little, but I don’t understand how to handle the loops, or selections in tap forms. I need to do this script to a handful of other fields as well. If I can get one to work, I feel confident I can modify it to make the others work. Any ideas?

    February 24, 2020 at 12:38 AM #39636

    Sam Moffatt
    Participant

    Off the top of my head, where:

    • players_linked_fieldId is the field ID of the “Link to Form” field in your Classes form.
    • players_fieldId is the field ID of the Players field in your Classes form.
    • players_linked_player_name_fieldId is the field ID of the players-linkedin field in your Players form.

      Three fields: link field, source field and destination field (in destination form).

      var players_linked_fieldId = 'fld-1234';
      var players_fieldId = 'fld-4321';
      var players_linked_player_name_fieldId = 'fld-1337';
      
      for (record in form.getRecords())
      {
        for (player in record.getFieldValue(players_fieldId).split(',').map(p => p.trim()))
        {
          let playerRecord = record.addNewRecordToField(players_linked_fieldId);
          playerRecord.setFieldValue(players_linked_player_name_fieldId, player);
        }
      }
      document.saveAllChanges();
      

      Something like that should work. Outer loop gets all of the records and iterates over them. Inner loop splits the text field on a comma and also trims the string (that’s the map(p => p.trim()) piece). Inside the loop you add a new record to the “Link to Form” field and set the player name on the inside to be the player from the string.

      None of this is tested, provided as is and it should work with a few tweaks. You’ll need to replace the field ID’s with your own values but apart from that it should be good enough to test. I’d recommend having Tap Forms duplicate the document and work from it first to make sure there aren’t any weird side effects.

Viewing 1 reply thread

You must be logged in to reply to this topic.