Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Create New Related Record in Portal Problem

Featured Replies

Hi,

I am trying to created a group of related records in a portal based on a JSON array I have parsed.  I have a bug where it only creates one related record in the portal and then creates a new parent record for the remaining # in the array.  If the array has 14 items I get in the portal for the related records and then get 13 new parent records.  Any idea what im doing wrong?

Set Variable [ $$json ; Value: Bid_Requests::AirbnbJSONRESPONSE ] 
Set Variable [ $fkey ; Value: Bid_Requests::PrimaryKey ] 
Set Variable [ $ItemCount ; Value: ValueCount ( JSONListKeys ( Bid_Requests::AirbnbJSONRESPONSE ; "object.response.response_json.explore_tabs[0].sections[0].listings" ) ) ] 
Set Variable [ $i ; Value: 0 ] 
If [ $ItemCount>0 ] 
Loop
Go to Layout [ “BidDetails” (Bid_Requests) ; Animation: None ]
Go to Object [ Object Name: "Airbnbgrid" ] 
Go to Portal Row [ Select: On ; Next ; Exit after last: On ]
New Record/Request
Set Field [ AirbnbSCRAPE::FK_BidRFH ; $fkey ] 
Set Field [ AirbnbSCRAPE::id ; JSONGetElement ( $$json ; "object.response.response_json.explore_tabs[0].sections[0].listings[" & $i & "].listing.id" ) ] 
Set Field [ AirbnbSCRAPE::city ; JSONGetElement ( $$json ; "object.response.response_json.explore_tabs[0].sections[0].listings[" & $i & "].listing.city" ) ] 
Set Field [ AirbnbSCRAPE::guest_label ; JSONGetElement ( $$json ; "object.response.response_json.explore_tabs[0].sections[0].listings[" & $i & "].listing.guest_label" ) ] 
Set Field [ AirbnbSCRAPE::localized_neighborhood ; JSONGetElement ( $$json ; "object.response.response_json.explore_tabs[0].sections[0].listings[" & $i & "].listing.localized_neighborhood" ) ] 
Set Field [ AirbnbSCRAPE::name ; JSONGetElement ( $$json ; "object.response.response_json.explore_tabs[0].sections[0].listings[" & $i & "].listing.name" ) ] Commit Records/Requests [ With dialog: Off ] 
Set Variable [ $i ; Value: $i+1 ] 
Exit Loop If [ $i ≥ $ItemCount ] 
End Loop
End If

 

Thanks,

In advance.

 

Tim

 

I only glanced at your script. But I see that it contains a New Record step within a loop. The New Record step will always create a new record in the active layout's table - which I believe is the parent table in your case. To create a child record via a portal, you only need to enter some data in the "ghost" row of the portal. However, when scripting the creation of child records, it is much better practice to work strictly at the data level and not rely on the presence of any layout objects such as a portal. That means going to a layout of a child table and looping there.

An alternative method of creating child records from the layout of parent is described here:
https://filemakerhacks.com/2011/07/31/magic-key-and-check-box-reporting/

 

  • Author

Not sure what you mean by "ghost" row? I just want to find the easiest way to add several new records to a portal via script.  Is there an easy way to do this without the magic key approach?

5 hours ago, TimJ said:

Not sure what you mean by "ghost" row?

I mean the first empty row in a portal based on a relationship that allows creation of related records in the child table. Entering data in this row will create a new child record and populate its foreign key field/s with the values from the current parent's match field/s - see: 
https://fmhelp.filemaker.com/help/18/fmp/en/index.html#page/FMP_Help%2Fcreating-relationships.html%23ww1142949
https://fmhelp.filemaker.com/help/18/fmp/en/index.html#page/FMP_Help/adding-duplicating-deleting-records.html

 

5 hours ago, TimJ said:

I just want to find the easiest way to add several new records to a portal via script. 

The easiest way is to add new records directly to the child table, not to the portal. As I tried to say earlier, it is also the better method (with one exception*). I am attaching a simple demo that shows how it can be done (you did not post an example of your JSON, so I had to make up my own).

ParseJSONtoChild.fmp12

 

---
(*) Records added through a portal remain uncommitted, allowing you to roll back the entire operation by reverting the parent record. This is known as being "transactional".

 

  • Author

Thanks so much.  Your example worked perfectly

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.