Capture Smart Service Error Message from Expression

If a Smart Service has a onError argument, can I capture the error message of what went wrong?  For example, the createUser SmartService has an onSuccess and onError arguments.  In the onSuccess, I can capture the created user with fv!user.  Which is great.  But in the onError, I don't see anything that will tell me what went wrong.

I know the system knows what went wrong because if I happen to wrap the call to the createUser call in a WebAPI, I can see in the "Details" section of the "Smart Service Executed" response it says, "The username requested is not available".  But I want to capture that text so that I can log/report it and I don't see a way to do that.  I want to know more than "It failed".  I want to be able to report what actually went wrong.

Thanks in advance,
Steve

  Discussion posts and replies are publicly visible

  • 0
    Certified Lead Developer

    Did you see that this smart service requires that it is executed in the context of an admin account? Running it inside a user interface does not make much sense.

    But, in general, I agree, the error cause should be available.

  • This was simply a trivial example to give some context to my question:  When running a smart service from an expression how does one capture what went wrong if/when it fails.

  • 0
    Certified Lead Developer
    in reply to steveb0007

    So, some smart service functions do return values if they fail. This would be documented. Like for a!startProcess

    https://docs.appian.com/suite/help/23.1/Start_Process_Smart_Service.html#node-outputs

  • In that case, it's actually returning a ProcessInfo about the Process that it indeed started.  If it FAILED to start the process I don't think it returns an error info about why.

    In my createUser example, I wrapped it in a WebAPI and it ran successfully the first time as expected.  I ran it again with the SAME parameters and, as you would expect, it failed because you can't have 2 users with the same username (obviously).

    What I am interested in, is how do you get at the error?  If I were to keep it in an API how can I report that error back to the calling process?  createUser doesn't seem to pass the error message in any form to onError (as far as I can tell)... and yet, the API tester (right side of screen) happily reports, "Dictionary errorMessage: "[The username requested is not available]" in the "Smart Services Executed" section of the tester.  I want to grab the text and include it in the a!httpResponse body (assuming I decide to leave it in an API).

    I'm trying to find out if anyone can concretely show me an example.  Otherwise, I have to assume the Appian system is not capable of performing this kind of error reporting.

    Example that I'm referring to:

    a!localVariables(
      local!value: a!fromJson(http!request.body),
      a!createUser(
        username: index(local!value, "username"),
        firstName: index(local!value, "firstName"),
        nickname: "",
        middleName: "",
        lastName: index(local!value, "lastName"),
        email: index(local!value, "email"),
        sendAccountCreationEmail: false,
        onSuccess: a!httpResponse(
          statusCode: 200,
          headers: {
            a!httpHeader(
              name: "Content-Type",
              value: "application/json"
            )
          },
          body: a!toJson(fv!user)
        ),
        onError: a!httpResponse(
          statusCode: 500,
          headers: {
            a!httpHeader(
              name: "Content-Type",
              value: "application/json"
            )
          },
          body: a!toJson(
            a!map(
              message: "User creation failed",
              error: "{I really should be able to report what went wrong here.}"
            )
          )
        )
      )
    )