Auto Populate a lookup field based on a User input

Auto Populate a lookup field based on a User input

HI

I have a form "Despatch" with fields
1. Despatch_ID
2. A lookup field named WH_ID (Linked with a form named Warehouse)
3. A lookup field named Material_ID (Linked with a form named Material)

and some other fields

I have another form for taking arrivals of material in Warehouse. The form named "Arrival" with the fields
1. A lookup field named Despatch_ID
2. A lookup field named Warehouse
3. A lookup field named Material_ID

and some other fields.

When i enter Despatch_ID in the "Arrival" form, I want to update the Arrival form with the same Warehouse and Material_ID as in Despatch form.

I wrote the following delug script
if(Despatch[ID == input.Despatch_ID].count() > 0)
{
temp = Despatch[ID == input.Despatch_ID];
temp1 = Material[ID == temp.Material_ID];
input.Material_ID = temp1.Material_ID;
        temp2 = Warehouse[ID == temp.WH_ID];
        input.WH_ID = temp2.WH_ID;
}

But it is returning undefined in Material_ID and saying the script is not correct for WH_ID as it is a string and ID is a BIGINT.

Please help for the same.