Skip to main content
Known Participant
August 8, 2026

Can we use a!syncrecords inside foreach tog sync records

  • August 8, 2026
  • 7 replies
  • 50 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!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

      )

    )

  )

)

7 replies

stefanhelzle0001
Brainy
August 8, 2026

No

kapils024874
Inspiring
August 8, 2026

The way you have structured your Web API this way because Appian evaluates smart service functions inside a!forEach local variables purely as data definitions, not as executable commands. 
I think this is probably the main reason why it is not working.

You can try moving this logic into a Process Model. Pass local!records into the process as an array, use a gateway to split the array by recordset, and route them to native Sync Records smart service nodes.

Known Participant
August 9, 2026

@kapils024874 
I dont want to use the process model is there a way I can do that with a!syncrecords itself to pass multiple records and its identifiers.

stefanhelzle0001
Brainy
August 9, 2026

The parameter “identifiers” is in plural on purpose. Just that list of IDs.

Known Participant
August 9, 2026

No, Its not just about the identifiers I want to pass multiple record types also into the a!syncrecords

kapils024874
Inspiring
August 9, 2026

If you only want to use a Web API for syncing multiple record type objects, here’s what I can suggest:
you must extract the identifiers into grouped arrays, abandon the a!forEach loop entirely, and hardcode the execution of each record type by nesting them within the onSuccess parameters.

The risk in this approach is that it only works for a fixed, predetermined list of record types  and will become an unmaintainable nightmare if you ever need to support a third or fourth record type dynamically.  


a!syncRecords(
recordType: recordType!Case, /* Hardcoded Record Type 1 */
identifiers: local!caseIds,
onSuccess: a!syncRecords(
recordType: recordType!Cover, /* Hardcoded Record Type 2 */
identifiers: local!coverIds,
onSuccess: a!httpResponse(
statusCode: 200,
headers: {a!httpHeader(name: "Content-Type", value: "application/json")},
body: a!toJson(
a!map(
success: true,
message: "Successfully synced Case and Cover records."
)
)
),
onError: a!httpResponse(
statusCode: 500,
body: a!toJson(a!map(success: false, message: "Failed syncing Cover records."))
)
)


 

harshas2775
Brainy
August 10, 2026

I would suggest to have different web apis for different record types and external system can call the webapi with respect to the record it needs to sync. This will enhance in debugging as well as performance monitoring in case of issues when designed for long term usage. You can follow this documentation for setting up the web APIs from within each record type itself.