I think there are two methods.
@Prashant Maheshwari 's post reminded me of the %%rid%% technique.
If the goal is to Create a parent record with no data entry from the user, then you would use a regular API_AddRecord API (post back if you need help with that) and populate a field called [Record ID# of Originating Child] with the Record ID# of the Child record that you launched from.
Then create a Pipeline to trigger on Add Record where the [Record ID# of Originating Child] is >0 to edit the Child record for that Record ID# and put the Record ID# of the Trigger Added Parent record into the field for Related Parent.
There will be a bit of a delay while the Pipeline runs. If you needed a faster reaction time, I think that you could use an "old fashioned" webhook or Action to update the child record as they will trigger very fast.
.... now if your intent is to put up an AddRecord form and have the user fill in some fields and manually save, then you could have a simple Add Record API and once again populate a field in the Parent Record with the Record ID# of the Originating Child.
The initial Add Record API would just be this.
URLRoot() & "db/" & [_DBID_PARENT] & "?act=API_GenAddRecordForm"
& "&_fid_250=" & [Record ID#] // populating the field called [Record ID# of the Originating Child]
But then instead of having the user save normally, you would get the user to click a special formula
Rich Text button with this code
var text RID = "%%rid%%";
var text EditChildToConnectToThisParent = URLRoot() & "db/" & [_DBID_CHILD]
& "?act=API_EditRecord&rid=" & [Record ID# of Originating Child]
& "&_fid_7=" & $RID;
var text DisplayNewParent = URLRoot() & "db/" & [_DBID_PARENT] & "?a=dr&rid=";
var text URL =
$EditChildToConnectToThisParent
& "&rdr=" & URLEncode($DisplayNewParent) & $RID;
"<a class='SaveBeforeNavigating' data-replaceRid=true style=\"text-decoration:none; background: #4b7097; border-radius: 5px; color: #ffffff; display: inline-block; padding: 0px 0px 0px 0px; width:100px; text-align: center; text-shadow: none; border: 2px solid #030404; font-size: 12px \"href='"
& $URL
& "'>Display Parent with Child Attached</a>"
//NOTE: The %%RID%% does not seem to like being URLEncoded.
But a better suggestion is to launch from the Child with this code here.
URLRoot() & "db/" & [_DBID_PARENT] & "?act=API_GenAddRecordForm"
& "&_fid_250=" & [Record ID#]
& "&ifv=1".. what extra suffix will do that will do is take away the save button (along with all the header stuff) and force the user to save with the provided Rich Text Formula button.
The Rich Text formula button will land the user on the Newly created parent and the child will be attached in the Report link field with it displays.
You can, of course play with the parameters of the Rich Text button to control the size of the font and the colour of:
the button,
the words,
and the border.
------------------------------
Mark Shnier (Your Quickbase Coach)
mark.shnier@gmail.com
------------------------------