Skip to main content
Solved

Add child record through parent form and redirect back to parent form in edit mode

  • July 30, 2024
  • 0 replies
  • 1221 views

Forum|alt.badge.img+2

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)

Best answer by MikeTamoush

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.

 

This topic has been closed for replies.

Forum|alt.badge.img+20
  • Registered
  • July 30, 2024

You need to take advantage of the function %%rid%%. This captures the newly created Record ID. However, the %%rid%% cannot be URLencode so in your case (i hid your app token for security reasons so fill it in appropriately):

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=xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
& "&_fid_48=" & $RID
& "&_fid_39=" & [Data Source 2] 
& "&_fid_25=" & [Brief description of data]
& "&_fid_42=" & [Approx # Interfaces]
& "&_fid_37=" & [Data Classification];

$url & "&rdr=" & URLEncode($RedirectNoRecordID) & $RID


Forum|alt.badge.img+2
  • Author
  • Registered
  • July 31, 2024

Hey Mike,

I tried using %%rid%% and the updated code. However, I'm getting this error when adding a child record while adding a parent record. It works as intended when I try to add a child while editing a parent record. Is it because the record ID # hasn't been created when adding the parent record? Is there any way to get around this, where I can click the add child button on the form, it created the parent record, takes the new record ID # and uses it to add the child record, and then redirect me back to the parent record in edit form.

 


Forum|alt.badge.img+20
  • Registered
  • July 31, 2024

The %%rid%% IS the way to get around it. Can you post your code? Also, can you post the URL in the browser, when that demand record not found error is shown?


MarkShnierYou
Forum|alt.badge.img+24

Mike, that %%RID%% only works with the rich text SaveBeforeNavigating syntax. I might try to answer if I find time, but no time right now. 


Forum|alt.badge.img+2
  • Author
  • Registered
  • July 31, 2024

URL in browser:
https://mdlz.quickbase.com/db/buayja58r?a=er&rid=%20id

Code (I've hidden the app token ID):

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#];

$url & "&rdr=" & URLEncode($RedirectNoRecordID) & $RID



Forum|alt.badge.img+20
  • Registered
  • Answer
  • July 31, 2024

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.

 


Forum|alt.badge.img+20
  • Registered
  • July 31, 2024

I just noticed something else, why is field 48 and 41 both set to the record ID? You should not be using [Record ID#] at all any more. It should always be instead, $RID. However, I believe this will only work to fill in the record ID in a single spot (Ive tried two spots and the second instance fails I believe). Do both field 41 and 48 need the Record ID? You should only need it in the related field.


Forum|alt.badge.img
  • Registered
  • August 14, 2024

The functionality I am looking for is - The users should be able to add multiple rows of &
[Data Source ] [Brief description of data] [Approx # Interfaces]  - [Data Source 2] [Brief description of data 2] [Approx # Interfaces 2] - ... and so on upto 15, and depending upon how many rows of data sources they add, those many number of rows should be filled in the child table under the same project name and record id