Error inserting value to linked field

Error inserting value to linked field

Hello,

I have a stateless form that is uses "insert into" command to populate two tables, "Contacts" and "Contact_History" in the "On Click" script of the "Submit" button.
 
First I insert data into the "Contacts" table. The "Contacts" table automatically adds a 'Contact_ID' value via an auto-numbering field.

Next I fetch that Contact_ID value (assigned to 'r') and use it to add linked data into the "Contact_History" table, attempting to populate the 'Contact_ID' field which is a look-up to the Contacts table.

Problem: It returns the error that the new Contact_ID value is not in the lookup list.
      "Error in add records task --> Reference field Contact_ID not having value (r)"

However if I substitute the command and try to add the same value 'r' to a non-look-up field ('Contact' - see lines 5+), it works fine.

It seems that the values are added to the Contact table, but the look-up list in the Contact_History is not updated.

Suggestions?

  1. insert into Contacts
    [
         Email = input.Email
         Mailing_List = input.Mailing_List
         Name_F = input.Name_F
         Name_L = input.Name_L
         Organization = input.Organization
         Type = input.Type
     ]







  2. // find record based on email/last name pairing:
    r = Contacts[(Email == input.Email && Name_L == input.Name_L)].Contact_ID;
    insert into Contact_History
    [


  3.     Contact_ID = r    // This returns an error stating that the value for r is not in the lookup list.
        Comments = input.Comments
        Description = input.Interest
        Name_L = input.Name_L
    ]




  4. //ALTERNATE CODE:
  5. insert into Contact_History


  6.      Contact = r          //This alternate code works: Contact is NOT a linked field
  7.      Comments = input.Comments
         Description = input.Interest
         Name_L = input.Name_L
    ]