AnsweredAssumed Answered

Auto create related records if they don't exist already

Question asked by JohnBrookes on Feb 15, 2018
Latest reply on Feb 15, 2018 by philmodjunk

I have two tables, Timesheet and Work.  Each Timesheet record can be associated with multiple Work records.  Each Work record will only be associated with one Timesheet record:

 

Timesheet:

ID

Staff ID

PG

 

 

Work:

ID

Date

Staff ID

PG

Hours

Timesheet:ID

 

What I want to do is add a new Work record, and if a Timesheet with matching Staff ID and PG exists, then make these related by putting the Timesheet:ID into the Work record.  But if there is no Timesheet with the same Staff ID and PG, I want to automatically create one and then put its Timesheet:ID into the Work record.

 

How should I do this?  Or, alternatively, am I being a complete idiot for wanting to do this?

Outcomes