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
  • Something that I've tried that seems to work is having a local variable such as local!error that defaults to false. In onSuccess use a!save(local!error,false) and in onError use a!save(local!error,true). Then in your a!buttonWidget(), have submit:not(local!error). This way if the evaluation results in an error, then the form won't submit.

  • 0
    A Score Level 1
    in reply to John M
    Hi johnm796,
    I modify my interface, as you suggested:

    = load(
    local!error:false,
    a!formLayout(
    label:"title",
    firstColumnContents: {
    myFields
    },
    buttons: {
    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Start",
    style: "PRIMARY",
    value: "start",
    saveInto:{
    a!writeToDataStoreEntity(
    dataStoreEntity: cons!myDataStore,
    valueToStore: local!mycdt,
    onSuccess: {
    a!save(
    local!error,false
    ),

    },
    onError: {
    a!save(
    local!error,true
    )
    }
    )

    },
    submit:not(local!error),
    validate:true,
    validationGroup: "checkSave"
    )
    }
    ),

    },
    validations: {
    a!validationMessage(
    message:if(toboolean(local!error),"not saved",""),
    validateAfter:"REFRESH"
    )
    },
    validationGroup: "checkSave"
    )

    )


    However,I test the error case in designer:it works and give me the message if local!error is true.
    If I test it on my process, the form has been submitted. Are there errors on my code?
    Thanks.
Reply
  • 0
    A Score Level 1
    in reply to John M
    Hi johnm796,
    I modify my interface, as you suggested:

    = load(
    local!error:false,
    a!formLayout(
    label:"title",
    firstColumnContents: {
    myFields
    },
    buttons: {
    a!buttonLayout(
    primaryButtons: {
    a!buttonWidget(
    label: "Start",
    style: "PRIMARY",
    value: "start",
    saveInto:{
    a!writeToDataStoreEntity(
    dataStoreEntity: cons!myDataStore,
    valueToStore: local!mycdt,
    onSuccess: {
    a!save(
    local!error,false
    ),

    },
    onError: {
    a!save(
    local!error,true
    )
    }
    )

    },
    submit:not(local!error),
    validate:true,
    validationGroup: "checkSave"
    )
    }
    ),

    },
    validations: {
    a!validationMessage(
    message:if(toboolean(local!error),"not saved",""),
    validateAfter:"REFRESH"
    )
    },
    validationGroup: "checkSave"
    )

    )


    However,I test the error case in designer:it works and give me the message if local!error is true.
    If I test it on my process, the form has been submitted. Are there errors on my code?
    Thanks.
Children