Hello,
I've been having some difficulty working with fetching records from a form based on a lookup field value in that form.
This is for a simple inventory system app for tracking sticks of RAM in our inventory by the RAM Model and Quantity. Types of RAM models are stored in their own "RAM_Models" form. The "RAM_Inventory" form has a RAM Model lookup field which allows you to select any model from the RAM_Models form and also a Quantity field for tracking total quantity. (There are other fields, such as Owner, which is also a lookup, but not directly relevant to this question).
What I am trying to do is fetch ALL records from RAM_Inventory that match the specific RAM_Model specified in the RAM_Model Lookup field in the RAM_Inventory form (so that I can then use a foreach to cycle through and total the quantity of that specific RAM model in RAM_Inventory).
The code looks like this:
- // get RAM Model string
- model = RAM_Models[ID = input.RAM_Model].Model;
- // get totals for that model from Inventory and Project tables
- modelRecords = RAM_Inventory[RAM_Model = model];
- // add up quantities
- totalInvQty = 0;
- for each record in modelRecords {
- totalInvQty = totalInvQty + record.Quantity;
- }
Now, after much googling and painful trial and error I discovered that the input.RAM_Model lookup field doesn't return a string corresponding to the Model field in the RAM_Models form, but rather some kind of special lookup ID (which is why Line 2 queries the Model field directly to get the string rather than this long ID BIGINT).
This seems to make it impossible to fetch all records in RAM_Inventory with the model specified in the lookup input field. Both of these return no records:
- modelRecords = RAM_Inventory[RAM_Model = input.RAM_Model];
and attempting to get the RAM Model string and query this way doesn't work either:
- model = RAM_Models[ID = input.RAM_Model].Model;
- modelRecords = RAM_Inventory[RAM_Model = model];
The latter gives me this error:
In Criteria left expression is of type BIGINT and right expression is of type STRING and the operator = is not valid
Is there any way to get around this so that I can fetch all records in RAM_Inventory that have the same model as specified in RAM_Models in their associated lookup field? Or is this simply not possible?