Skip to main content
scottg846876
March 3, 2025
Solved

Posting data with an alternate primary key

  • March 3, 2025
  • 2 replies
  • 0 views

I have a REST service that posts a lot of data to a table in Appian (136k+ rows).  The problem is the primary key in the service is not the same primary key that Appian is using.  I cannot match the keys because, the service's key is unpredictable.  Government data, yea! 

 For my REST post I simply need it to find the record with a matching value (if it exists) then update it, or else create a new record.

a!localVariables(
  local!value: cast(
    'recordType!{b44d0eeb-090e-4c8f-b858-1f684423adbc}DCQ Weekly Extract',
    a!fromJson(http!request.body)
  ),
  a!writeRecords(
    records: local!value,
    /*
    * Construct an HTTP response to return to the caller
    */
    onSuccess: a!httpResponse(
      statusCode: 200,
      /*
      * Set an HTTP header that tells the client that the body of the response will be in JSON format
      */
      headers: {
        a!httpHeader(name: "Content-Type", value: "application/json")
      },
      /*
      *In the response body, return the records created or updated
      */
      body: a!toJson(fv!recordsUpdated)
    ),
    onError: a!httpResponse(
      statusCode: 500,
      headers: {
        a!httpHeader(name: "Content-Type", value: "application/json")
      },
      body: a!toJson(
        a!map(
          message: "Write request has failed",
          error: fv!error
        )
      )
    )
  )
)

Best answer by stefanhelzle0001

Try to query the data with that external key from the record. Then, update the incoming data with that internal primary key using a!update(). Then, write that modified data.

2 replies

stefanhelzle0001
March 3, 2025

Try to query the data with that external key from the record. Then, update the incoming data with that internal primary key using a!update(). Then, write that modified data.

karumurua531442
March 3, 2025

hi [mention:438bef055cfe4f439c77fa941df228d9:e9ed411860ed4f2ba0265705b8793d05]  as [mention:a11f77a729fb4db2af76b09948583328:e9ed411860ed4f2ba0265705b8793d05] mentioned you need to check your data using some wherecontains() with external data is present  in your  Internal data and the update