Skip to main content
fantacyc0001
May 17, 2021
Question

How can I get the process instance errors and save it into any process variable?

  • May 17, 2021
  • 26 replies
  • 1 view

Dear community,

I have a start process web api, the process is updating the metadata table.

My facing issue is that API response success even when write to data store entity error.

The expected result should be when process executing error, we can expose the process instance error in web api response body.

Therefore, how can I get the process instance error? then I can save it into process variable, and in the api, we can get it through ProcessInfo.

Thanks in advance for your answers.

26 replies

danny.verb
May 17, 2021

a!startProcess() has two parameters which help, onSuccess and onError. onError happens when a node in the process model runs into an execution error and onSuccess happens when the activity chaining for you process completes and none of those nodes hit an error. For your use case, it seems like you need to add an a!httpResponse() in the onError parameter.

fantacyc0001
May 18, 2021

In my case, when write to data store entity node encounter  error, a!startProcess still response success code 200, it didn't flow into onError condition, that's why I have this asking.

stefanhelzle0001
Brainy
May 18, 2021

Did you enable chaining at least up to that node?

BTW, why does this node fail in the first place?

davel001150
May 17, 2021

Write to datastore also has an onError output that can be configured.

fantacyc0001
May 18, 2021

yes, you are right. but I use the write to data store entity node in the process, and webapi start this process, not use a!writeToDataStoreEntity() in the interface directly, and my problem is how can I capture the process instance error message and configure back in onError()/onSuccess() outputs?

July 10, 2021

Hello ,

I am new to Appian and facing same problem, I am trying to find a way to capture the Process Instance error to a process variable.

Are you able to achieve this task?

stewart.burchell
May 18, 2021

You can write your own error handling around this. It's not great if you want to surface the details of an error but you can at least handle this gracefully.

Your process model needs to be chained. You can add one or more Boolean flags and default them all to false e.g. isDataValid, isDataWrittenToDatabase, Then as the process proceeds you can toggle these to 'true' e.g. if you have a validation step then you can update the 'isDataValid' to true. The same for the Write To Datastore. If this is successful the next thing you would do would be to update the 'isDataWrittenToDatabase' flag to true.

These pv!s will then be available to your WebAPI and you can then customise your HttpReponse according to what those flags are set to. As I said this will at least handle failures gracefully. Getting the specifics of the failure of a Write To Datastore node would be a lot more complicated (probably as an asynchronous process that trawls the logs in some fashion).

I also echo [mention:126a676c85024855948336691b0a7b92:e9ed411860ed4f2ba0265705b8793d05] - never trust the data being sent to your WebAPI. Always conduct the necessary validations on it before attempting to write to the database (or write to a staging table with no validation, and then conduct an off-line validation exercise before committing to your operational tables).

stewart.burchell
May 18, 2021

An afterword: please consider raising a request to Appian Engineering to allow developers to conduct their own error handling so that you can do exactly what I think you're looking to do (the equivalent of a 'try'/'throw'/'catch' pattern).

csteward
May 18, 2021

What would be nice is if the Write to Data Store Entity node had a "Pause Node on Error" parameter, as does the Query DB node.  With Query DB, this allows you to continue the process (false setting) and define smooth error handling.  In older processes we have utilizing Query DB, with external databases that do go down on occasion, we have this node continuing to a Receive Message event on error - say 100 processes fail in an hour long DB outage, one click of an admin process sends messages to all waiting sub processes, back online instantly - it's a beautiful thing!

komalj3844
July 10, 2021

Hi,

can you please try with this code 

a!startProcess(
processModel: cons!Process_model,
processParameters: a!fromJson(
http!request.body
),
onSuccess: a!writeToDataStoreEntity(
dataStoreEntity: cons!Datastoreentity,
valueToStore: {},
onSuccess: a!httpResponse(
statusCode: 200,
headers: {
a!httpHeader(name: "Content-Type", value: "application/json")
},
body: a!toJson(
fv!processInfo
)
),
onError: a!httpResponse(
statusCode: 500,
headers: {
a!httpHeader(name: "Content-Type", value: "application/json")
},
body: a!toJson(
{
error: "There was an error recived while inserting data"
}
)
)
),
onError: a!httpResponse(
statusCode: 500,
headers: {
a!httpHeader(name: "Content-Type", value: "application/json")
},
body: a!toJson(
{
error: "There was an error starting the process"
}
)
)
)

please user a!writetodatastore smartservice on success of a!startprocess and the error will be received in case failed