Forum Discussion

samvedi's avatar
samvedi
Qrew Trainee
4 months ago

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.

     

  • 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

  • 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.

     

    • samvedi's avatar
      samvedi
      Qrew Trainee

      Hi Mike,

      I am now running into some issues with the button. It doesn't seem to be stable and doesn't work consistently. Most of the times, it works, but sometimes it takes me to this page:

       Is there any way I can make this work consistently?

      Here is the button 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=xxxxxxx"
      & "&_fid_48=" & $RID
      & "&_fid_39=" & [Data Source 2] 
      & "&_fid_25=" & [Brief description of data]
      & "&_fid_42=" & [Approx # Interfaces]
      & "&_fid_37=" & [Data Classification]
      & "&_fid_44=" & [Project Name];

      "<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #783c7c; 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
      & "'>Add Data Source</a>"

       

  • 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.

     

  • 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?

  • 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. 

    • samvedi's avatar
      samvedi
      Qrew Trainee

      I wouldn't mind using a rich text SaveBeforeNavigating syntax if it gets the job done. Can I make a rich text button with this capability instead of a formula URL button? Would that work?  

      • MarkShnier__You's avatar
        MarkShnier__You
        Icon for Qrew Legend rankQrew Legend

        Trey this post here and let us know. 

        https://community.quickbase.com/discussions/quickbase-discussions/re-new-functionaility-rid/28799#bm4466dd0f-403f-4f24-94d8-4ac7128081ae

    • MikeTamoush's avatar
      MikeTamoush
      Qrew Commander

      Oh shoot. I forgot the other important part (besides save before navigating). Ill post it for him. Thanks Mark!

  • 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


  • 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.

    • samvedi's avatar
      samvedi
      Qrew Trainee

      Thanks so much Mike and Mark! It seems to be working as intended now. I'm not sure where I got field 48 from so I removed it. The button seems to be working when adding child records while adding a parent record through a single form.

    • vyb's avatar
      vyb
      Qrew Member

      Hi, I am working with Sam on this and while this helped us resolve the issue, now I want to add multiple data sources under the same parent record by clicking the button just once, is this possible?

  • vyb's avatar
    vyb
    Qrew Member

    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

    • MarkShnier__You's avatar
      MarkShnier__You
      Icon for Qrew Legend rankQrew Legend

      :)

      Truthfully, I would simply abandon the formula URL approach and set up a pipeline to create the child records. 

      Or, another stupid simple alternative (I'm a big fan of stupid simple) would be to set up a Legacy Style form for adding or editing the parent and include an embedded report of the child records and have the user add (or edit) the child records directly on the Legacy Form In Grid Edit mode.  

      The reason I suggest using  Legacy Style form is that at present the new style forms do not the functionality to add children in Grid Edit mode.

      • vyb's avatar
        vyb
        Qrew Member

        Hey Mark, Thank you so much for your help. I'm a big fan of stupid simple ideas too!!! I'll try both options and see what works best for me!