I've encountered an issue using Smartsheet API. The script occasionally creates duplicate rows in the Smartsheet table, resulting in multiple identical entries for the same data.
Current Script Logic:
- The script collects data about the parent row.
- A request is sent to add a row to the table via the API method
api.smartsheet/2.0/sheets/{sheetId}/rows
. - The script waits for a response with the ID of the created row.
- If no ID is received (error or empty response body):
- A 2-minute wait period is initiated.
- The API search method
api.smartsheet/2.0/search?query=
is called to find the row by its content. - If the row is found (status code 200), its ID is retrieved, and the script continues.
- If the row is not found, another attempt is made to add it using
api.smartsheet/2.0/sheets/{sheetId}/rows
.
- This process repeats up to 5 times before the script terminates.
Issue:
The error SSS_REQUEST_TIME_EXCEEDED (request timeout exceeded) occurs in NetSuite. However, the key problem is:
- When adding a parent field, a timeout error sometimes occurs.
- A search request using
api.smartsheet/search?query=
returns a status code 200. However, the row does not actually exist in the table, even after waiting for 2 minutes. - When trying to add the row again, it is successfully added. As a result, duplicate rows appear in the table.
Example: I try to add a row with the value "IT3775," receive a timeout error, wait for 2 minutes, search for "IT3775," get a status code 200 and an empty body (the row is still not there), then try to add the row again and end up with duplicates.
I've provided the script execution logs (some fields are hidden as a security measure) ErrorLog, as well as screenshot from the SmartSheet table so that you can see the problem clearly.
Example of duplicating a row in a SmartSheet table
- line 2347 - First attempt to add a parent line. (An error was occurred in the script, but eventually this field appears in the SmartSheet table).
- line 2348 - Second attempt to add a parent line (successful).
- line 2349 - Child fields.
P.S.I will provide the script code if needed.
Questions:
How can I prevent duplicate rows?