Can we use a!syncrecords inside foreach tog sync records
This an Webapi where I will be getting the recordtype and its respective identifiers to sync those specific rows,
So I tried putting it inside for each but its not syncing Im getting success code as 200 but not syncing.
Input:
{
"records": [
{ "recordset": "case", "recordId": 1 },
{ "recordset": "cover", "recordId": 7 }
]
}
Output received:
{ "success" : true, "result" : [ { "keys" : [ "status", "syncedIdentifiers" ], "values" : [ 0, 1 ] }, { "keys" : [ "status", "syncedIdentifiers" ], "values" : [ 0, 7 ] } ] }
In output if you see under “Values” you will see 0 which is local!result intitially set to 0 but as i could see its entering into a!syncrecord by the onsuccess is not getting updated why and why its not syncing?
a!localVariables(
/* Parse the incoming JSON */
local!request: a!fromJson(http!request.body),
/* Expecting { "records": [ { "recordset": "...", "recordId": "..." }, ... ] } */
local!records: index(local!request, "records", {}),
local!result:0,
/* Build sync results for each record */
local!syncResults: a!forEach(
items: local!records,
expression: a!localVariables(
/* Determine record type based on `recordset` */
local!recordType: a!match(
value: index(fv!item, "recordset", ""),
equals: "case",
then: 'recordType!Case',
default: null()
),
local!identifier: index(fv!item, "recordId", null()),
local!syncResult:if(
or(isnull(local!recordType) , isnull(local!identifier)),
"fail",
a!syncRecords(
recordType:local!recordType,
identifiers: local!identifier,
onSuccess: a!save(local!result, 1),
onError: a!save(local!result, 2)
)
),
a!map(
keys: {"status", "syncedIdentifiers"},
values: {local!result, local!identifier}
),
)
),
/*local!syncResults*/
/* Build HTTP response */
a!httpResponse(
statusCode: 200,
headers: {
a!httpHeader(
name: "Content-Type",
value: "application/json"
)
},
body: a!toJson(
a!map(
success: true,
result: local!syncResults
)
)
)
)
