Parsing HTTP Response

I am struggling with parsing the HTTP response.  I thought fv!result in the rule that called the integration would allow me to access the body of the response.  However, I am getting errors.  The three values I am trying to access are highlighted below.  Screenshots of the function where I call the integration and the response from the call are shown below.  I would like the three values stored in local variables so I can display the text messages to the user.  Thank you in advance!

                         rule!CreatePatientResource(
                           givenName:local!firstName,
                           familyName:local!surName,
                           gender:local!gender,
                           dateOfBirth: local!dateOfBirth,
                           onSuccess:
                           {
                             a!save(local!registrationErrorMessage,null),
                             a!save(local!registrationComplete,true()),                 
                             a!save(local!registrationConfirmationMessage, 
                               concat(tostring(local!firstName), " ",tostring(local!surName)," was successfully registered"))

                           },
                           onError: {
                              /*Handle HTTP error */
                             a!save(local!registrationErrorMessage, fv!error.message)
                           }
                         )

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    And what errors do you get?

    For me, your code and your requirements do not match.

    Where is this "onSuccess" coming from. Do you try to call an integration which you configured to "Modifies Data" just inside some expression code?

  • The onSuccess/onError was shown as rule-inputs when we selected "Override and define all error conditions" option.  

    This is the integration that we are trying to call and obtain results from.

  • Error:Could not display interface. Please check definition and inputs.  Interface Definition: Expression evaluation error:

    Here is the sequence 

  • 0
    Certified Lead Developer
    in reply to Rochester

     
    Error:Could not display interface. Please check definition and inputs.  Interface Definition: Expression evaluation error:

    This error appears to be more with how the data is being handled after your integration call.

    Your code for calling the integration itself appears to be good.

    If you could share the code for your interface that would help diagnose the problem

  • 0
    Certified Lead Developer
    in reply to Rochester

    In your code, in the onSuccess, I do not see that you try to fetch any data from the API call result.

    Find here the documentation about how to call an integration.

    https://docs.appian.com/suite/help/24.1/Call_an_Integration.html

    Then, I suggest to create a very simplified test interface to make a root cause analysis easier.

  • Hello Naveen:

    Here is the code.... If I remove the highlighted line, it works but I need the ID from the integration's response (see image from previous post). 

    Thank you for your help.

    a!sectionLayout(
    label: "Patient Information",
    contents: {
    a!textField(
    label: "First Name",
    labelPosition: "ABOVE",
    placeholder: "Enter Patient's Given Name",
    value: local!firstName,
    saveInto: {
    local!firstName,
    a!save(local!registrationErrorMessage, null)
    },
    refreshAfter: "KEYPRESS",
    required: true,
    disabled: local!registrationComplete
    ),
    a!textField(
    label: "Family Name",
    labelPosition: "ABOVE",
    placeholder: "Enter Patient's Surname Name",
    value: local!surName,
    saveInto: {
    local!surName,
    a!save(local!registrationErrorMessage, null)
    },
    refreshAfter: "KEYPRESS",
    required: true,
    disabled: local!registrationComplete
    ),
    a!textField(
    label: "Gender",
    labelPosition: "ABOVE",
    placeholder: "Enter Patient's Gender",
    value: local!gender,
    saveInto: {
    local!gender,
    a!save(local!registrationErrorMessage, null)
    },
    refreshAfter: "KEYPRESS",
    required: true,
    disabled: local!registrationComplete
    ),
    a!dateField(
    label: "Date of Birth",
    labelPosition: "ABOVE",
    value: local!dateOfBirth,
    saveInto: {
    local!dateOfBirth,
    a!save(local!registrationErrorMessage, null)
    },
    required: true,
    disabled: local!registrationComplete
    ),
    a!textField(
    label: "Student Identifier",
    labelPosition: "ABOVE",
    placeholder: "Enter Student Identifier",
    value: local!studentIdentifier,
    saveInto: {
    local!studentIdentifier,
    a!save(local!registrationErrorMessage, null)
    },
    refreshAfter: "KEYPRESS",
    required: true,
    disabled: local!registrationComplete
    ),
    if(local!registrationComplete,
    {
    /* */
    a!richTextDisplayField(
    value: {
    a!richTextImage(image: a!documentImage(document: a!iconIndicator(icon: "STATUS_OK"))),
    a!richTextItem(text:local!integrationResponse, color:"ACCENT", size:"MEDIUM")
    /*a!richTextItem(text:"has been successfully registered", size:"MEDIUM"),*/
    }
    ),
    a!richTextDisplayField(
    value: {
    a!richTextImage(image: a!documentImage(document: a!iconIndicator(icon: "STATUS_OK"))),
    a!richTextItem(text:local!registrationConfirmationMessage, color:"ACCENT", size:"MEDIUM")
    /*a!richTextItem(text:"has been successfully registered", size:"MEDIUM"),*/
    }
    ),
    },
    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Register Patient",
    saveInto: { {
    rule!CreatePatientResource(
    givenName:local!firstName,
    familyName:local!surName,
    gender:local!gender,
    dateOfBirth: local!dateOfBirth,
    onSuccess:
    {
    a!save(local!registrationErrorMessage,null),
    a!save(local!registrationComplete,true()),
    a!save(local!registrationConfirmationMessage,
    fv!result.headers.location),
    /*concat(*/
    /*tostring(local!firstName),*/
    /*" ",*/
    /*tostring(local!surName),*/
    /*" was successfully registered"*/
    /*)*/
    a!save(local!integrationResponse, fv!result.body.id)

    },
    onError: {
    /*Handle HTTP error */
    a!save(local!registrationErrorMessage, fv!error.message)
    }
    )
    }
    },
    style: "SOLID",
    disabled: not(isnull(local!registrationErrorMessage)),
    loadingIndicator: true,
    validate: true
    )
    }
    )
    )
    },
    validations: if(isnull(local!registrationErrorMessage),
    {},
    local!registrationErrorMessage
    )
    )

  • 0
    Certified Lead Developer
    in reply to Rochester

    What do you mean with 

    If I remove the highlighted line, it works

    What does work? Do you see any error message?

    That line looks good for me.

  • 0
    Certified Lead Developer
    in reply to Rochester

     ,

    Your code looks good and I dont see any problem . Since you are getting the response from your headers after the integration to debug it will be worth capturing the whole response from fv!result to your local variable instead of indexing it right away and check if the response is indeed as you are expecting it to be.

  • The interface works - I don't see any error message.

  • 0
    Certified Lead Developer
    in reply to Rochester

    So, my typical approach is, to reduce complexity when I am stuck. Build a separate test interface with just the minimum things. Then I suggest to save the whole API response to a local variable. Then drill into it, step by step. It is so easy to get this wrong.

  • As suggested, I tried to create a simple test-interface .... But I am trying to figure out how to display the result returned by the integration because I am getting the following errors

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function a!richTextDisplayField [line 5]: A rich text item or rich text list item in a rich text display component [label=""] has an invalid value for "text". Text can only be of type date, date and time, decimal, rich text icon, integer, rich text item, text, time, or user. Received RichTextDisplayField.

    {
      a!localVariables(
        local!integrationResponse,
        a!formLayout(
          a!richTextDisplayField(
            labelPosition: "COLLAPSED",
            value: {
              a!richTextItem(text:local!integrationResponse)
            }
          ),
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "Submit Test Data",
                style: "OUTLINE",
                saveInto: {
                  rule!CreatePatientResource(
                    givenName: "Susan",
                    familyName: "James",
                    gender: "Female",
                    dateOfBirth: "1989-02-23",
                    onSuccess: {
                      a!save(local!integrationResponse, fv!result)
                    },
                    onError: {
                      /*Handle HTTP error */
                      a!save(
                        local!integrationResponse,
                        fv!error.message
                      )
                    }
                  )
                }
              )
            },
            align: "START",
            marginBelow: "NONE"
          )
        )
      )
    }

  • 0
    Certified Lead Developer
    in reply to Rochester

    Hello  ,

    It appears you have missed the keywords on your form layout on the code you shared.
    Try this and check if you get any data on your local!integrationResponse and share here if you need help diagnosing this further

    a!localVariables(
        local!integrationResponse,
        a!formLayout(
          contents:{
            a!richTextDisplayField(
            labelPosition: "COLLAPSED",
            value: {
              a!richTextItem(text:tostring(local!integrationResponse))
            }
          ),
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "Submit Test Data",
                style: "OUTLINE",
                saveInto: {
                  rule!CreatePatientResource(
                    givenName: "Susan",
                    familyName: "James",
                    gender: "Female",
                    dateOfBirth: "1989-02-23",
                    onSuccess: {
                      a!save(local!integrationResponse, fv!result)
                    },
                    onError: {
                      /*Handle HTTP error */
                      a!save(
                        local!integrationResponse,
                        fv!error.message
                      )
                    }
                  )
                }
              )
            },
            align: "START",
            marginBelow: "NONE"
          )
          }
        )
      )

Reply
  • 0
    Certified Lead Developer
    in reply to Rochester

    Hello  ,

    It appears you have missed the keywords on your form layout on the code you shared.
    Try this and check if you get any data on your local!integrationResponse and share here if you need help diagnosing this further

    a!localVariables(
        local!integrationResponse,
        a!formLayout(
          contents:{
            a!richTextDisplayField(
            labelPosition: "COLLAPSED",
            value: {
              a!richTextItem(text:tostring(local!integrationResponse))
            }
          ),
          a!buttonArrayLayout(
            buttons: {
              a!buttonWidget(
                label: "Submit Test Data",
                style: "OUTLINE",
                saveInto: {
                  rule!CreatePatientResource(
                    givenName: "Susan",
                    familyName: "James",
                    gender: "Female",
                    dateOfBirth: "1989-02-23",
                    onSuccess: {
                      a!save(local!integrationResponse, fv!result)
                    },
                    onError: {
                      /*Handle HTTP error */
                      a!save(
                        local!integrationResponse,
                        fv!error.message
                      )
                    }
                  )
                }
              )
            },
            align: "START",
            marginBelow: "NONE"
          )
          }
        )
      )

Children
No Data