You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

FileMaker JSON解析循环迭代时记录被覆盖问题求助

Troubleshooting Your FileMaker JSON Import Script

It sounds like you're hitting two common pitfalls with FileMaker JSON parsing and record creation—let's break this down and fix it step by step.

1. Check if Your ID Field is a Global Field

The most likely culprit here is that your grievanceSubmissions::ID field is set to Global Storage. Global fields in FileMaker share their value across all records in the table. So every time you set the ID in a new record, you're overwriting the value for all existing records, which results in all records showing the last ID from your JSON array.

How to Fix:

  • Open Manage Database (File > Manage > Database)
  • Go to the Tables tab, select grievanceSubmissions
  • Go to the Fields tab, find the ID field
  • Uncheck the Global storage option (under the "Options" button or in the field properties)
  • Save your changes and re-run the script.

2. Fix Your Submission Count Calculation

Your current script uses JSONListKeys to count submissions, but submissions is an array (not an object with named keys). JSONListKeys returns the keys of an object, so it will return an empty list for an array—meaning your $grievanceCount might be incorrect (or you're relying on a lucky accident in debugging!).

How to Fix:

Replace your count calculation with one of these two options:

Option A: Use JSONListValues (count array elements directly)

Set Variable [ $grievanceCount ; Value: ValueCount ( JSONListValues ( $json ; "submissions" ) ) ]

JSONListValues returns each element in the array as a separate line, so ValueCount gives you the correct number of submissions.

Option B: Use the "total" value from your JSON (cleaner, since it's provided)

Your JSON already includes a total field with the count of submissions, so you can use that directly:

Set Variable [ $grievanceCount ; Value: JSONGetElement ( $json ; "total" ) ]

3. Optional: Add Error Checking

To avoid unexpected behavior if the URL request fails, add a check after Insert from URL to ensure $json isn't empty:

Insert from URL [ Select; with dialog: Off ; $json; "web address"]
If [ IsEmpty ( $json ) ]
    Show Custom Dialog [ "Error" ; "Failed to retrieve JSON data." ]
    Exit Script [ Text Result: "Error" ]
End If

Revised Script

Putting it all together, your fixed script would look like this:

Insert from URL [ Select; with dialog: Off ; $json; "web address"]
If [ IsEmpty ( $json ) ]
    Show Custom Dialog [ "Error" ; "Failed to retrieve JSON data." ]
    Exit Script [ Text Result: "Error" ]
End If

Set Variable [ $grievanceCount ; Value: JSONGetElement ( $json ; "total" ) ]
Set Variable [ $i; Value: 0 ]

If [ $grievanceCount > 0 ]
    Loop
        New Record/Request
        Set Field [ grievanceSubmissions::ID ; JSONGetElement ( $json ; "submissions[" & $i & "]id" ) ]
        Commit Records/Requests [ With dialog: Off ]
        Set Variable [ $i ; Value: $i + 1 ]
        Exit Loop If [ $i ≥ $grievanceCount ]
    End Loop
End If

This should resolve the issue where all records end up with the last ID—you'll now get a unique record for each submission in your JSON array.

内容的提问来源于stack exchange,提问作者Dskip1199

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 06:19:50