Search code examples
zohosubformzoho-delugelookupfield

Auto populating a sub form based on purchase order id in zoho creator


I am new to Creator and building an e-procurement application.

I have two forms - one for Purchase Order and a second one for Goods received. On the Goods received form, I have a sub form with fields for product, quantity and vendor name. These fields should auto populate when purchase order id is added. It is lookup to purchase order form. The purchase order id in goods received is of big integer type and order id in purchase form is of type text.

Here's the code I have tried:

purchase_order_id = input.Purchase_Order_ID;
input.Goods.clear();

if (purchase order id != null)
{
    purchase_order_records = Purchase_Order[ID == purchase_order_id];

    for each order record in purchase_order_records
    {
        goods_row = Map();
        goods_row.put("Product_Name", order_record. Items.Product);
        goods_row.put("Vendor_Name", order_record.Vendor);
        goods_row.put("Quantity_Requested", order_record. Items.Quantity);
        input.Goods.insert(goods_row);
    }
}

If someone could point out where I went wrong, it would be helpful.

Thank you!


Solution

  • Please define the proper variable name and values. I updated the script, and this code is working fine. I tested it. You can change it a little according to your form and subform.

        purchase_order_id = input.Purchase_Order;
        if (purchase_order_id != null)
        {
            clear Goods ;
            purchase_order_records = Purchase_Order[ID == purchase_order_id];
            purchase_order_recordsItems= purchase_order_records.Items;
            for each order_record in purchase_order_recordsItems 
            {       
    
                goods_row =Goods_Received.Goods();
                goods_row.Product_Name=order_record.Product_Name;
                goods_row.Vendor_Name=order_record.Vendor_Name;
                goods_row.Quantity_Requested=order_record.Quantity_Requested;           
                input.Goods.insert(goods_row); 
            } 
         }