Check the write to Data Store after submit a interface

Hi All,

I have an interface where I use the function a!writeToDataStoreEntity when I click on the submit button.

In the function a!writeToDataStoreEntity, I declare a variable where save the value for the  onSuccess or onError . If this variable is onError, I don't want to submit the interface and advice the user about the error. Is there a way to make this?

This is an example of my case

a!formLayout(
firstColumnContents: {
allMyfields
},
buttons: {
a!buttonLayout(
primaryButtons: {
a!buttonWidgetSubmit(
label: "Start",
style: "PRIMARY",
value: "start",
saveInto: {
a!writeToDataStoreEntity(
dataStoreEntity: cons!myDataStore,
valueToStore: local!myCDT,
onSuccess: {
a!save(
local!resultWriteToDB,
"Data Inserted"
),
a!save(
ri!newBBSID,
fv!storedValues.ID
)
},
onError: {
a!save(
local!resultWriteToDB,
"Data not Inserted"
)

}
)

},
validate:true,
validationGroup: "checkSave"
)
}
),

},
validationGroup: "checkSave",
validations: {
a!validationMessage(
message:if(local!resultWriteToDB="Data Inserted","saved",""),
validateAfter:"SUBMIT"
)
}
)

 

 

Thanks in advance.

  Discussion posts and replies are publicly visible

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

    If you still have a genuine scenario where you want to do it in the from itself, it can still be done.

    However you need to keep in mind below before going ahead:

    1. validationMessage when configured as validateAfter : "SUBMIT", will invoke the validation and present the message successfully as long as you are not using any ri! or local! that is being updated in the Button where(on click) you need this validation.
    2. Above will work for both buttonWidgetSubmit as well as buttonWidget
    3. In case you need to invoke a validation based on a parameter you are updating on the button click, you need to do the following: -
      1. Change your buttonWidgetSubmit to a buttonWidget, this will allow you to be on the form while your parameter is updated.
      2. Configure the submit parameter on the buttonWidget, use the above updated parameter to decide whether you want to stay on the form or submit the form.
      3. Based on updated parameters define your validation Messages.
      4. Use different sections with validationGroup mapped to different buttons if required


    I have a scenario where I want to restrict the Edit action if the selected value(id) is already in the list of items being edited. This restriction is not applicable to other submit button (add, which in this case will serve as copy). So I need to capture or update a parameter (similar to error message in your case). There is another validation required for both that you should not be able to proceed if none of the ids is selected.

    I am attaching a simple version of the code snippet to elaborate it.

    You can update your button configs and get the error message from WTDS and validate your form similarly -


    load(
      local!action: "",
      local!activeEditIds: {
        1,
        2,
        3
      },
      local!selectedId: 1,
      a!formLayout(
        firstColumnContents: {
          a!textField(
            label:"Active Ids being Edited",
            value: local!activeEditIds
          ),
          a!integerField(
            label: "Selected Id",
            value: local!selectedId,
            saveInto: local!selectedId
          ),
          a!buttonLayout(
            primaryButtons: {
              a!buttonWidget(
                label: "Add",
                style: "PRIMARY",
                value: "Add",
                saveInto: {
                  local!action
                },
                submit: true
              )
            },
            secondaryButtons: {
              a!buttonWidget(
                label: "Edit",
                value: "Edit",
                saveInto: {
                  local!action
                },
                submit: not(
                  contains(
                    local!activeEditIds,
                    local!selectedId
                  )
                ),
                validationGroup: "EditAction"
              )
            }
          ),
          a!sectionLayout(
            validations: {
              a!validationMessage(
                message: if(
                  rule!APN_isEmpty(
                    local!selectedId
                  ),
                  "You must first select an existing item to commence this action",
                  ""
                ),
                validateAfter: "SUBMIT"
              )
            }
          )
        },
        validations: {
          a!validationMessage(
            message: if(
              and(
                local!action = "Edit",
                contains(
                  local!activeEditIds,
                  local!selectedId
                )
              ),
              "There is already an active process of this type",
              ""
            ),
            validateAfter: "REFRESH"
          )
        },
        validationGroup: "EditAction"
      )
    )