How to add Single subform Row of Data based on each input of 1 field (Barcode scan)

How to add Single subform Row of Data based on each input of 1 field (Barcode scan)

Hello,

I can't seem to get my head wrapped around getting a subform to populate data another form properly.

I seemed to have coded something that technically populates, but it creates multiples of the same data, when I only need 1 row per entry of data in a single field, which is essentially a barcode scan field.

Form 1:

Called: Add Product

Has:

Prod Barcode
Product Name
Price

Form 2:

Called: Create Sale

Has:

Single Field called Main Barcode - this field will get the barcode scan, then be the lookup number of the product details above to populate the sub field.

Sub form called Sale Items with:

Sale Barcode
Sale Product
Sale Price

I looked at video tutorials and knowledge bases and have come up with the following workflow for user input:

prodinfo = Add_Product[prod_barcode == input.main_barcode];
prodrow = Create_Sale.sale_items();
for each prod_barcode in Add_Product
{
prodrow.sale_barcode = prodinfo.prod_barcode;
prodrow.sale_prod_name = bookinfo.prod_name;
prodrow.sale_price = prodinfo.prod_price;
prodsalecollection = Collection();
prodsalecollection.insert(prodrow);
input.sale_items.insert(prodsalecollection);
    }

What happens is it actually puts an entry in, but like 15 rows of it in the sub form.

I only need to scan the product once, it populates the details in the subform and then I will have the main barcode field wipe and become the focus, ready to scan the next barcode to create the next row of data.

Anybody know what I did wrong or missed to have it create more than 1 row of the same data?

I also have a "Total" field where I coded that if the sale price sub form field is not null, to then add up each row price. the code:

var_total = 0.0;
for each  sale_items in sale_items
{
if(row.sale_price != null)
{
var_total = var_total + row.sale_price;
}
}
input.main_total = var_total;

This doesnt update the total when the entries are inputted.
    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ




                              ご検討中の方