Add child record through parent form and redirect back to parent form in edit mode
Hi,
Is there a way I can add child record(s) when adding a parent record through a single form? I am trying to collect general info in the parent form and then have the ability to click a button to add a selected data source into the child table. Once that data source is added, it should automatically redirect me back to the parent form in edit mode as I left it and I should be able to add as many data sources as I want.
I tried using a formula button which I found in the exchange, however, it only works as intended when editing a parent record. It doesn't work when adding a parent record because the record ID hasn't been created yet so it can't redirect back to the parent form in edit mode. Here is the code in the formula URL button that I currently use in the form to add a child record:
var text redirect=URLRoot()&"db/"&Dbid()&"?a=er&rid="&[Record ID#]; // REDIRECT TO THE FORM IN EDIT
var text url = URLRoot() & "db/" & [_DBID_PROVIDER_DETAILS] & "?a=API_AddRecord&apptoken=d4y5wt4betuct5khdpyxbvqp7p6&_fid_48=" & [Record ID#]
& "&_fid_39=" & [Data Source 2] & "&_fid_25=" & [Brief description of data] & "&_fid_42=" & [Approx # Interfaces] & "&_fid_37=" & [Data Classification];
$url & "&rdr=" & URLEncode($redirect)
Sorry, Mark is right, I forgot a very important part. It needs to be a formula rich text. Also, you need to have data-replaceRid=true and SaveBeforeNavigating in the button code as shown below.
Try changing your field to a formula rich text and using this code:
var text RID = If([Record ID#]>0, ToText([Record ID#]), "%%rid%%");
var text RedirectNoRecordID=URLRoot()&"db/"&Dbid()&"?a=er&rid="; // REDIRECT TO THE FORM IN EDIT
var text url = URLRoot() & "db/" & [_DBID_PROVIDER_DETAILS] & "?a=API_AddRecord&apptoken=xxxxxx"
& "&_fid_48=" & $RID
& "&_fid_39=" & [Data Source 2]
& "&_fid_25=" & [Brief description of data]
& "&_fid_42=" & [Approx # Interfaces]
& "&_fid_37=" & [Data Classification]
& "&_fid_41=" & [Record ID#]; //why is field 41 here? what is field 48 then? This is incorrect but we can only set one field to $RID, so pick the related field."<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #1ba802; border-radius: 5px; color: #ffffff; display: inline-block; padding: 4px 6px; text-align: center; text-shadow: none; border: 2px solid #1ba802; font-size: 12px \"href='"
& $url
& "&rdr=" & URLEncode($RedirectNoRecordID) & $RID
& "'>Button Words here</a>"//You can use any rich text button code, but you must include the data-replaceRID=true.