Solved
validation problem on avoid duplicate value for insert and non-exist value for update
a!localVariables(
local!insert:false,
local!update:false,
a!formLayout(
label: "Username",
contents: {
a!textField(
label: "username",
labelPosition: if(
ri!readOnly,
"ADJACENT",
"ABOVE"
),
value: ri!username.username,
saveInto: ri!username.username,
refreshAfter: "UNFOCUS",
validations: {
if(
a!queryEntity(
entity: cons!usernameConstant,
query: a!query(
fetchTotalCount: true,
pagingInfo: a!pagingInfo(
startIndex: 1,
batchSize: 1
),
logicalexpression: a!queryLogicalExpression(
operator:"OR",
filters: {
a!queryFilter(
field: "username",
operator: "=",
value:(ri!username.username),
applyWhen:not(isnull(ri!username.username))
),
}
)
)
).totalCount > 0,
local!insert:true,
local!update:true
),
}
),
a!textField(
label: "gender",
labelPosition: if(
ri!readOnly,
"ADJACENT",
"ABOVE"
),
value: ri!username.gender,
saveInto: ri!username.gender,
refreshAfter: "UNFOCUS",
validations: {}
),
a!columnsLayout(
columns: {
a!columnLayout(
contents: {
a!textField(
label: "Password",
labelPosition: if(
ri!readOnly,
"ADJACENT",
"ABOVE"
),
value: ri!username.password,
saveInto: ri!username.password,
characterLimit: 255,
readOnly: ri!readOnly
)
}
)
}
),
},
buttons: a!buttonLayout(
primaryButtons: {
a!buttonWidget(
label: "Insert",
saveInto:(
a!writeToDataStoreEntity(
dataStoreEntity: cons!usernameConstant,
valueToStore:(ri!username)
),
),
disabled:local!insert,
submit: true,
style: "PRIMARY",
),
a!buttonWidget(
label: "update",
saveInto:(
a!writeToDataStoreEntity(
dataStoreEntity: cons!usernameConstant,
valueToStore:ri!username,
),
),
disabled:local!update,
submit: true,
style: "PRIMARY"
),
a!buttonWidget(
label: "delete",
saveInto:(
a!deleteFromDataStoreEntities(
dataToDelete: {
a!entityDataIdentifiers(
entity: cons!usernameConstant,
identifiers:{ri!username.username},
)
}
)
),
submit: true,
style: "PRIMARY"
)
},
secondaryButtons: {
a!buttonWidget(
label: "Cancel",
value: true,
saveInto: ri!cancel,
submit: true,
style: "NORMAL",
validate: false
)
},
showWhen: or(
isnull(
ri!readOnly
),
not(
ri!readOnly
)
)
)
)
)
For line 17 validation part nearby, i wish the button insert will not work if it find the duplicate username already in database, and disable update button for the username can't be found, that is what i put in the validation part of if condition sentences, however, it report error with "Expression evaluation error at function a!textField", then how can I do?
