I did some poking around in that file and I got a solution that works. I'll post it here in case anyone else wants to do something similar.
At the end of SetFormSettings I added:
IF p_web.FormSettings.action = Net:InsertRecord
p_web.ssv('PromotionFormSate', p_web.FormState)
ELSE
p_web.DeleteSessionValue('PromotionFormSate')
END
IF p_web.IfExistsSessionValue('PromotionFormTempCreated')
p_web.DeleteSessionValue('PromotionFormTempCreated')
END
If I was using a form to create the child record I could probably just read p_web.FormSettings.ParentState when writing the child record. But I'm using a button on a child browse, so I needed to save the form state in a session value
At the start of CancelForm I added:
IF p_web.FormSettings.action = Net:ChangeRecord AND p_web.gsv('PromotionFormTempCreated') = 1
p_web.OpenFile(SQLFile)
PMS:PromotionID = p_web.gsv('PMS:PromotionID')
Bind('PromotionID', PMS:PromotionID)
Bind('Result', ErrorCode#)
SQLFile{PROP:SQL} = '&Result = CALL [Inventory].[DeletePromotion](&PromotionID[IN])'
p_web.CloseFile(SQLFile)
END
The template does add code to delete the record if the session value [ProcedureName]:Primed is set to 1, but I wanted to delete it my way.
Right before the child record is added we check it we need to create the parent:
IF p_web.IfExistsSessionValue('PromotionFormSate')
FormStateString = p_web.gsv('PromotionFormSate')
p_web.RequestData.WebServer._GetSettingsQueue(p_web.SessionID, FormStateString, TempFormState)
IF TempFormState.action = Net:InsertRecord
p_web.OpenFile(Promotions)
p_web.ssv('PromotionForm_CurrentAction', Net:ChangeRecord)
p_web.SessionQueueToFile(Promotions)
SetNull(PMS:EventID)
IF p_web.AddFile(Promotions) = Level:Benign
p_web.RequestData.WebServer._Wait()
p_web.RequestData.WebServer._GetSettingsQueue(p_web.SessionID, FormStateString, TempFormState)
p_web.RequestData.WebServer._SettingsQueue.Settings.action = Net:ChangeRecord
Put(p_web.RequestData.WebServer._settingsQueue)
p_web.RequestData.WebServer._Release()
p_web.DeleteSessionValue('PromotionFormSate')
p_web.ssv('PromotionFormTempCreated', 1)
END
p_web.CloseFile(Promotions)
END
END
If you adding the child using a form then something similar would likely go in the PostInsert embed.
Edit: I wasn't comfortable putting file I/O in a critical section so I changed the last embed. I get the form state twice just in case, but the critical section is very small.