a!deleteFromDataStoreEntities within onsuccess a!writeToDataStoreEntity in a WebApi

Hello,

 I have a problem in a webApi.

I have to put inside onSuccess of a!writeToDataStoreEntity  a a!deleteFromDataStoreEntities. When I execute it, the deletion in the database is correct but the web api returns an error 500  besides this error:

Not a valid Web API Response. Received: [Lcom.appiancorp.core.data.Record;@2a857aff.

The code is:

a!writeToDataStoreEntity(
dataStoreEntity: cons!TABLA_PRUEBA,
valueToStore: local!Datosguarda,
onSuccess:
with(


a!deleteFromDataStoreEntities(
dataToDelete: {
a!entityDataIdentifiers(
entity: cons!TABLA_PRUEBA2,
identifiers: local!idToDelete
)
},
deletionComment: loggedInUser() & " deleted id " & local!idToDelete,
onSuccess: a!httpResponse(
statusCode: 200

),
onError: a!httpResponse(
statusCode: 500,
headers: {
a!httpHeader(
name: "Content-Type",
value: "application/json"
)
},
body: a!toJson(

error:"There was an error writing to the data store"
}
)
)
)


),
onError: a!httpResponse(
statusCode: 500,
headers: {
a!httpHeader(
name: "Content-Type",
value: "application/json"
)
},
body: a!toJson(
{
error:"There was an error writing to the data store"
}
)
)
)

Do you know why this happens?

Regards, and thank you very much

  Discussion posts and replies are publicly visible

  • I am running into this as well.  We want to first write to an audit table and then call a start PM.  I think you can only do one thing in a WebAPI.  So maybe start a PM that does those two actions.

  • Smart Service functions are special functions because they can have side effects - they can update or delete data in a database or start a process. Because of this, Appian limits any expression in a Web API or saveInto to only allow evaluating one smart service. See the Smart Services documentation for more information. 

    As the other commenter mentioned, the best way to work around this is to use a process model instead of the write to data store smart service. Use the Web API to start a process. Then, you can perform any logic or operations as nodes in the process model.