Hi, Sorry if the title is a bit confusing, but basically I have a Vehicles Table with [v_id] as the key, every vehicle is assigned a user (only 1 per vehicle), which is stored in Vehicles[user] (Email column type),
I have couple of other tables related to Vehicles called Maintenance, Service, Registrations all these tables have [v_id] as ref type column
Instead of a drop down to manually associate which vehicle this particular Maintenance/Service/Registrations Record is connected to can I use USEREMAIL() in some way to:
Get USEREMAIL()
Check Which Vehicles[v_id] (key) has this USEREMAIL() in the Vehicles[user] column
and Return that [v_id] as the initial value?
Basically When a user wants to for example add a new maintenance record it will automatically figure out what vehicle this user is connected to and use that [v_id] by default?
Vehicles[user] image:
Maintenance[v_id] image:
Any help would be greatly appreciated
Hi
You may want to know which user was the last one to use a vehicle, using the USEREMAIl() expression.
Similarly, you may want to retrieve some information depending on this vehicle using a LOOKUP expression.
If so, please refer to this excellent post:
you may be interested in the section โHow do I get the last row of this thing only?โ
Please see also:
Hi, Iโm actually familiar with that post Iโm using it for another function in the app, but for this specifically I just want to
Get USEREMAIL()
Check Which Vehicles[v_id] (key) has this USEREMAIL() in the Vehicles[User Email]
and Return that record?
Ps. One user email can only have only one vehicle and one vehicle can only have one assigned email so it is unique
Get the v_ID attached to the last entry of the user:
LOOKUP(
MAX(
SELECT(
tableEntries[_ROWNUMBER],
(USEREMAIL()=[User Email] )
)
),
"tableEntries",
"_ROWNUMBER",
"V_ID"
)
Thanks but I ended up going with this as the initial value
LOOKUP(USEREMAIL(),โTABLEโ,โEMAIL COLUMNโ,โKEYโ)
ie: LOOKUP(USEREMAIL(),โVehiclesโ,โuserโ,โv_idโ)
if something jumps out at you where this approach might give me trouble in the future please tell me, Iโm fairly inexperienced so sometimes I stumble onto answers that I donโt fully understand XD
Hi @Thilina
Your expression is correct.
Nonetheless, something is pretty unclear to me: how do you update the โv_idโ column in this table ?
My first understanding was that you didnโt have it, and then that you were looking for a straight way to get it ?
EDIT : minor change
in this case all I wanted to do was find what [v_id] is associated with the email thats the same as USEREMAIL() I didnโt need to update it, sorry if that wasnโt clear.
Now when I add a new row to my maintenance table it automatically finds the [v_id] (foreign key) of the vehicle the USEREMAIL() is assigned to
Previously when I add a new maintenance record :
Now:
Main Vehicle Table:
Maintenance Table:
Good job then
User | Count |
---|---|
16 | |
10 | |
8 | |
5 | |
5 |