How to validate form based on integration result

we have an interface where we are call an integration (passing data provided by the user in that interface) on submit button.

If integration got failed, then we need to display a validation message on one of the text field in the interface. else if it got succeeded then form has to submit.

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to sureshk

    Hi Suresh,

    If you want to call and validate the service response at Submit button and you don't want to proceed to next interface in case of failure, i think we need to put validation rules so that when service has failed it should not allow form to be submitted.

    You could try to implement below logic, to stop form being submitted in case of service failure:

    a!localVariables(
    local!success: {},
    {
    a!sectionLayout(
    contents: {
    a!textField(
    label: "Service Input",
    value: ri!integrationInput,
    saveInto: ri!integrationInput,
    validations: if(
    local!success,
    {},
    "Service Failure Message"
    )
    ),

    },

    ),
    a!buttonArrayLayout(
    buttons: {a!buttonWidget(
    label: "Submit",
    style: "PRIMARY",
    saveInto: {
    a!save(
    local!success,
    rule!integrationCall(
    ri!integrationInput
    ).success
    )
    },
    submit: true,
    validate: true
    )}
    )}

  • It did not work.

    since local!success is not true initially, on button click validation is applied on textField and validation message will be displayed before calling the rule!integrationCall() and local!success will never become true.

  • 0
    Certified Lead Developer
    in reply to sureshk

    I do not recommend to go that way. You would need to implement some complex logic for saveInto and validations to catch all cases. Try to go the process route.