Help with form submission using code

Hello, I’ve been having trouble using the no code option to submit my form so I’m trying it manually using code. The code below doesn’t seem to work at all, but I’ll post it so you can get an idea of what I’m trying to do.

export function btnSubmit_click(event) {

//Get values from input boxes
let strProductID = $w(“#txtItemID”).text;
let strTitle = $w(“#inputTitle”).value;
let strName = $w(“#inputName”).value;
let strEmail = $w(“#inputEmail”).value;
let strPhone = $w(“#inputPhone”).value;
let strLink = $w(“#inputLink”).value;
let boolLyrics = $w(“#cboxLyrics”).value;
let boolCoverArt = $w(“#cboxCoverArt”).value;
let boolInstagram = $w(“#cboxInstagram”).value;
let strComments = $w(“#richComments”).value;

//Set values to variables
$w(“#dataProjects”).setFieldValue(“product”, strProductID);
$w(“#dataProjects”).setFieldValue(“title”, strTitle);
$w(“#dataProjects”).setFieldValue(“name”, strName);
$w(“#dataProjects”).setFieldValue(“eMail”, strEmail);
$w(“#dataProjects”).setFieldValue(“phone”, strPhone);
$w(“#dataProjects”).setFieldValue(“link”, strLink);
$w(“#dataProjects”).setFieldValue(“lyrics”, boolLyrics);
$w(“#dataProjects”).setFieldValue(“coverArt”, boolCoverArt);
$w(“#dataProjects”).setFieldValue(“instagram”, boolInstagram);
$w(“#dataProjects”).setFieldValue(“comments”, strComments);

//clear fields
$w(“#inputName”).value = “”;
$w(“#inputEmail”).value = “”;
$w(“#inputPhone”).value = “”;
$w(“#inputLink”).value = “”;
$w(“#richComments”).value = “”;
$w(“#cboxLyrics”).value = “”;
$w(“#cboxCoverArt”).value = “”;
$w(“#cboxInstagram”).value = “”;
$w(“#richComments”).value = “”;

//show success message
$w(“#txtSuccess”).show();

}

Here’s what I’m wanting to do:

  1. I do I save it, and save it as a new record.

  2. After the form is submit it and fields are cleared, how do I prepare to have the form entered again for another new record?

  3. Is there a better, more efficient way to write the code?

  4. Do I need any error control?
    And one last thing. Where the user enters the information, they are on a Dynamic Page, which shows the current product. What I’d like to do is create a field in the dataset that will say, “Hey, here’s a reference for the product they’re looking at and interested in.” I couldn’t figure out how to create the reference and set it. So, as shown in the first line of code, I’ve got a Text label, that grabs an ID field I created. The code puts that into a variable and saves it. I would like to use code to connect them directly to each other.

let strProductID = $w(“#txtItemID”).text;

Thank you much for the help!