Add a child record and redirect to form for editing

  • 1
  • 2
  • Question
  • Updated 4 years ago
  • Answered

API_GenAddRecordForm is not ideal for what I am trying to do - create a few records with specific names as fast as possible.

I am trying to use formula URL button with API_AddRecord followed by rdr, and I need help to capture Record ID# of the new child for rdr.

In case it helps, table structure Estimates<Worktitles<Tasks. From Estimates form, I can create a new record in Worktitles called Other/General. Can you please help me to complete the formula:

URLRoot() & "db/" & [_DBID_WORK_TITLE_AREA] & "?a=API_AddRecord&_fid_47=" & URLEncode ([Estimate ID#])&

"&_fid_6=Other/General &_fid_58=" & URLEncode([Other/General WT #]) &

"&rdr="&URLEncode(URLRoot() & "db/" & [_DBID_WORK_TITLE_AREA] &"?a=er&rid=" &[NEW WORKTITLE ID#])





Photo of Arkady

Arkady

  • 142 Points 100 badge 2x thumb

Posted 4 years ago

  • 1
  • 2
I suggest either suffixing your AddRecord formula with &disprec=1

Which will display the newly created record and then the user can click Edit.

Or else, why nor use use the API GenAddRecordForm instead of AddRecord. That will put up the Add record form and still pre-populate certain fields, but the user can complete the remaining data entry manually before saving.

I have never seen a post in this forum as to how the get that record ID, as it's not known until after the record is saved.
Photo of Arkady

Arkady

  • 142 Points 100 badge 2x thumb
Mark,

Thank you, I did not notice disprec parameter until you suggested it.

Just another thought - description of AddRecord says that rid is one of its Response Values, and it comes up when no rdr is specified.

Do you think to capture AddRecord response as a text, and then use QB text functions to pull out rid value?

If you think this is a non-starter, I will use disprec.

Kind regards,

Arkady
Sorry, I don't know how to capture a response value ..., but if you want the user to do immediate data entry, why not just put up the Add Record form instead of creating the record and then trying to redisplay it in edit mode,.
Photo of Jeremy

Jeremy

  • 20 Points
I've retrieved the record ID with a line of JavaScript and used it to create a second record linked to the first. You could use it in any other API call or URL. The basic structure, substituting in the formulae above, but not tested, would be:

"javascript:"
& "var addRecord1='" URLRoot() & "db/" & [_DBID_WORK_TITLE_AREA] & "?a=API_AddRecord&_fid_47=" & URLEncode ([Estimate ID#])& "';"

& "$.ajax({url: addRecord, async: false, success: function(xml){var x=xml.getElementsByTagName('rid'); var recordID1 = x[0].childNodes[0].nodeValue;"

& "var editRecord ='" URLRoot() & "db/" & [_DBID_WORK_TITLE_AREA] &"?a=er&rid=' + recordID1 + ';"
& "window.location.href = editRecord;"
 } });"

When retrieving the record ID from the xml, you could check for an error and display a message if the API call has failed.
Photo of Arkady

Arkady

  • 142 Points 100 badge 2x thumb
Jeremy,

Thank you very much. Just to check whether I understood your answer correctly - can I put this code into a URL-formula field and fire it up via a URL button in a record editing form?

Kind regards,

Arkady
Photo of Jeremy

Jeremy

  • 0 Points
Hi, yes you can. I can't guarantee that the code will work first time, but I've used this approach and it does work.