Auto-Populate Fields in Parent Record by Evaluating Multiple Records from Related Children Records
I have 12 fields on a parent page that I would like to auto-populate based on the values in fields from multiplerecords in a related record.
For example, I have six fields that I want to auto-populate:
- Serum1Collected [AcuteSerumCollected] = Yes or No
- Serum1CollectedDate [AcuteSerumCollectedDate] = Date when the acute serum was collected
- Serum2Collected [ConvalescentSerumCollected] = Yes or No
- Serum2CollectedDate [AcuteSerumCollectedDate] = Date when the convalescent serum was collected
- CSFCollected = Yes or No
- CSFCollectedDate = Date when the CSF was collected
The criteria for auto-populating these two fields occur in two fields of the children records. These two fields are:
Over 20 records (children) may exist for each parent. I need to search for a key word in the child fields above. A script will run when the button is clicked. The script should go to the related child page and search all of the records there to see if any of the following statements are true:
In any of the child records ....
- If IllnessPhase = "Acute" AND SampleType = "Serum", THEN Serum1Collected = "Yes" AND Serum1Collected Date = DateCollected
- If IllnessPhase = "Convalescent" AND SampleType = "Serum", THEN Serum2Collected = "Yes" AND Serum2Collected Date = DateCollected
- If SampleType = "CSF", THEN CSFCollected = "Yes" AND CSFCollected Date = DateCollected
I don't know how to make the script evaluate all of the records in the child page, especially when the child records are updated or more child records (tests) are added. How would the script be written?