Get prefix of field, get distinct list, insert list as new records in new form

Get prefix of field, get distinct list, insert list as new records in new form

I'm trying to get fetch records in a form, get the first section of data from one of the text fields (everything before a "-"), then filter out duplicates, then use that list to make new entries in a new form. Here's what I think it should look like but it doesn't work:
  1. void insertUniqueList()
  2. {
  3. var = form1[ID !=0].textField1.getPrefix("-").getAll().distinct();
  4. for each index uniqueValue in var
  5.         {
  6. x = insert into newForm
  7.         [
  8.         newField = uniqueValue
  9.         ];
  10.     }
  11. }