Skip to main content
Known Participant
August 8, 2026
Question

Sync record via Webapi a!syncrecord with foreach()

  • August 8, 2026
  • 4 replies
  • 41 views

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!{e3830fb1-0602-4c99-954f-bdaa94db2eb1}CRP_Case',

        default: null()

      ),

      local!identifier: index(fv!item, "recordId", null()),

      local!syncResult:if(

        or(isnull(local!recordType) , isnull(local!identifier)),

       "fail",

     

        a!syncRecords(

          recordType:'recordType!{e3830fb1-0602-4c99-954f-bdaa94db2eb1}CRP_Case',

          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

      )

    )

  )

)

4 replies

stefanhelzle0001
Brainy
August 8, 2026

You can only call a single smart service function like a!syncRecords in a web API. I suggest to feed it all record IDs at once instead of using a foreach.

kapils024874
Inspiring
August 8, 2026

I have posted my comments on this one
 

 

Known Participant
August 9, 2026

Hi Stefan

Its not about the record type ids its about the different record type which I want to pass into a!syncrecords instead of using a process model

peter.lewis
Employee
August 10, 2026

Like others have said, a Web API can only execute a single smart service function at a time (in this case, only one a!writeRecords()). I think your best bet is to use a process, but in the other thread you mentioned you don’t want to use a process - can you give some more context why?