Process Model Error reporting via API

We have an  POST API on Appian that is being called to perform user related task ( add, remove, update, activate, deactivate) based on the data sent to the API. The API works fine as its a Cast and the API response of the Cast is being being sent back to the API initiator. However when there is an error the response is sent as an email alert how can the error be sent as an api response. For eg 

There is a problem with task “Deactivate User” in the process “PPL_IG Deactivate User Profile”

Problem:  An error occurred in executing an Activity Class.

Details:  The user [test.abc] you are trying to deactivate is invalid or does not exist.

Recommended Action:  Examine the activity class to correct the error and then resume.

How do i capture the "Details:  The user [test.abc] you are trying to deactivate is invalid or does not exist." from the error message received via email? 

  Discussion posts and replies are publicly visible

Parents Reply Children
  • Are you using a WebAPI to do this activity ? If you are then you can programmatic control the HTTP response and messages going back to the consumer based on the outcome of the validation step.

  • Yes i am using WEB API to do this activity and my error response is

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

    "status"  

    But this does not report the error back but an empty string

    pv": {
    "deactivateResponse": "",
    "deactivateUser": [

    Am i missing something?

  • The alert you are getting is from the Appian Smart Service in Process - so the process model has generated the alert and presumably the process model instance has now stopped. Presumably the PV's are not filled due to this alert. By validating the userid in the WebAPI you can send the invalid response back to the consumer before calling the process model to deactivate / update users based on the validation you've done in the webAPI. I'll try to knock up some sample code that might help

  • with(
      
      local!fromJson: a!fromJson(http!request.body),
       
      /*Validate the request details*/
      local!validate: /* RESULT OF THE USER VALIDATION*/ 
    				  /* one option could be to call isusernametaken() passing in the input user id */
    				  /* if this returns false then you can programatically pass back an error */ 
    				  /* you'd want to try and make sure that the user id exists in Appian and is valid for the update user smart service to work in process */
      ,
      
      /*Start Process if all ok or respond with validation error*/
      local!result: if (local!validate,
      
    	/*REQUEST VALID*/
    	/* Logic that starts the Process - passing back the result */
    	
    	a!startProcess(
    		processModel: /* Your user update model */, 
    		processParameters /* Input params */, 
    		onSuccess: 
    			a!httpResponse_17r4(
    				statusCode : 200,
    				headers: {
    					a!httpHeader(name: "Content-Type", value: "application/json"),
    					a!httpHeader(name: "Correlation-ID", value: tostring(index(http!request.headers, "Correlation-ID", null())))
    				},
    				body: a!toJson(
    					{
    						fv!processInfo.pv, /*Plus other data items as required*/
    					}	
    				
    		, 
    		onError: 
    			a!httpResponse_17r4(
    				statusCode: 400,
    				headers: {
    					a!httpHeader(name: "Content-Type", value: "application/json"),
    					a!httpHeader(name: "Correlation-ID", value: tostring(index(http!request.headers, "Correlation-ID", null())))
    				},
    				body: a!toJson_17r1(
    			{
    				resource: index(http!request, "url", null()),
    				httpStatusCode: 400,
    				message: "There was an error starting the process", /*or something similar */
    				title: "Error Starting Process"         /*or something similar*/    
    			}
    			)
    		)
    	),
    	
    	/*ELSE - invalid request as the user doesnt exist */
    	a!httpResponse_17r4(
    				statusCode: 400,
    				headers: {
    					a!httpHeader(name: "Content-Type", value: "application/json"),
    					a!httpHeader(name: "Correlation-ID", value: tostring(index(http!request.headers, "Correlation-ID", null())))
    				},
    				body: a!toJson_17r1(
    			{
    				resource: index(http!request, "url", null()),
    				httpStatusCode: 404,
    				message: "The requested user id is not valid", /*or something similar */
    				title: "Invalid User Id"         /*or something similar*/    
    			}
    			)
    		),
    	
    	
       
      local!result
    )

    Hope the above helps - I think you want to try and trap that the user is valid before trying any smart service updates on that user id. **EDIT - the code has been copied and cribbed from something we do for write to data store so is probably missing commas or closing brackets - and obviously needs bringing up to current appian function versions **

  • Your pointers did help and we are able to get the error and success response in the API  body but  when getting all groups and users the json is converted in to string format is there a way to get the output in json

    What we are currently getting is 

    getAllGroups": [
    "groupName: ACO Administrators",
    "description: ",
    "groupName: ACO All Users",
    "description: ",
    "groupName: Application Users",
    "description: Members of this group will be able to use applications exposed through the applications portal, but do not have permission to use the designer interface.",

    What we are looking for is something in the below format

    getAllGroups": [
    {
    "groupName: ACO Administrators",
    "description: ",
    }
    {
    "groupName: ACO All Users",
    "description: ",
    }
    {
    "groupName: Application Users",
    "description: Members of this group will be able to use applications exposed through the applications portal, but do not have permission to use the designer interface.",
    }

  • have you tried looking at the a!toJson function ? If your response from the process model is an array of CDT then I think a cast might be what you are looking for... possibly ... I will admit I have not had too much experience with json strings.