Get Row ID as default for form data

Get Row ID as default for form data

davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0
edited August 2020 in Free community support

I currently have a page setup to enter notes about a transaction. This is 2 tables. A note table and an invoice table. The note table has 3 columns. ID, inv_id, note.

How can I get the form to auto-populate the row ID in the form to submit to the note table?

    $(document).ready(function() {
        var editor = new $.fn.dataTable.Editor({
            ajax: 'php/table.id.php',
            table: '#idRequest',
            fields: [
                {
                    "label": "Notes:",
                    "name": "daily_notes.note",
                    "type": "textarea",

                },
                {
                    "label": "Note ID:",
                    "name": "daily_notes.note_id",
                    "type": "readonly",
                    "def": "disc_rq_activations.ID", <----- I know this doesnt work. 

                },


            ]
        });

Answers

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0
    edited August 2020

    oh forgot to add that I have this as well.

    columns: [
       {data: "disc_rq_activations.ID", editField: "daily_notes.note_id"}
    

    Not inserting note_id into db

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    You wouldn’t create the ID on the client-side - have the server-side do it (make it an auto incrementing primary key in the database).

    Allan

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

    The ID is already in the DB for the Note_ID. It would be row[0] in this example.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    I don't quite get it I'm afraid. You have both ID and note_id. You said in your initial post:

    How can I get the form to auto-populate the row ID in the form to submit to the note table?

    Were you actually referring to the note_id for the field that you want to auto populate? If so, where are you getting the value from that you want to populate it with?

    Allan

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

    The note_id is the ID of the row. I have a leftjoin. The join is notes table and the main table is the item table. So the item ID lets say is 20 then note_id when inserted should be 20. If that makes sense lol.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    A bit... :). So where is the item id coming from? Do you have that in a variable somewhere?

    Allan

  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0

    So the ID is coming from the row that is pulled. It is included in the variable for disc_rq_activations.ID

    columns: [
                      {data: "disc_rq_activations.ID", editField: "daily_notes.note_id"},
                      {data: "disc_rq_activations.Invoice_"},
                      {data: "disc_rq_activations.Tracking_"},
                      {data: "disc_rq_activations.Qty"},
                      {data: "disc_rq_activations.Product_SKU"},
                      {data: "disc_rq_activations.Product_Name"},
                      {data: "disc_rq_activations.Unit_Rebate"},
                      {data: "disc_rq_activations.Related_Product"},
                      {data: "disc_rq_activations.Related_SKU"},
                      {data: "disc_rq_activations.Related_SN"},
                      {data: "disc_rq_activations.Related_Cost"},
                      {data: "disc_rq_activations.Related_Price"},
                      {data: "disc_rq_activations.Rate_Plan"},
                      {data: "disc_rq_activations.Customer"},
                      {data: "disc_rq_activations.Sales_Person"},
                      {data: "disc_rq_activations.Sales_Person_ID"},
                      {data: "disc_rq_activations.Sold_On"},
                      {data: "disc_rq_activations.Invoiced_At"},
                      {data: "disc_rq_activations.Original_Invoice"},
                      {data: "disc_rq_activations.Original_Sales_Date"},
                      {data: "disc_rq_activations.Contract_"},
                      {data: "disc_rq_activations.SOC_Code"},
                      {data: "disc_rq_activations.SOC_Code_2"},
                      {data: "disc_rq_activations.Extra_Field"},
                      {data: "disc_rq_activations.Port_Number"},
                      {data: "disc_rq_activations.Region"},
                      {data: "disc_rq_activations.District"},
                      {data: "disc_rq_activations.Vendor_Account_Name"},
                      {data: "daily_notes.note"},
    
  • davidjmorindavidjmorin Posts: 101Questions: 31Answers: 0
    edited August 2020

    So basically what Id like is when a note is input that it inserts the ID into the note_id field. This is how I reference it and join them in the table.

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Sorry, I'm still a bit confused here. You've got a row, where you want to get the note_id from, but you also want to insert a row, referencing it? Are you using a child table here or something?

    Can you give me a link to the page you are working on please, or perhaps just show me the full Javascript? I'm missing how this should all link together.

    Allan

This discussion has been closed.