avoid insert duplicate information to database and give a hint to the user

Sorry, i keep looking for ways to not let user insert duplicate username to the database, but always fails, i know primary key as username can't be repeatedly insert in to the database by its service, but i just want

to give user a hint, and tell him can't register same username others used before and let it not to update to the back end database by its smartservice, then how can I do?

{

label: "Insert",
saveInto:(
a!writeToDataStoreEntity(
dataStoreEntity: cons!usernameConstant,
valueToStore:(ri!username)
),
),

submit: if(ri!username.username in local!rule.username
,false,true),
style: "PRIMARY",

}      OR

label: "Insert",

saveInto:(

if(

ri!username.username in local!rule.username,

{},
a!writeToDataStoreEntity(
dataStoreEntity: cons!usernameConstant,
valueToStore:(ri!username)

)
),
),

submit: true,
style: "PRIMARY",

  Discussion posts and replies are publicly visible

Parents Reply Children
  • a!localVariables(
    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: {}
        ),
        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)
               ),       
               ),
               
            submit: if(rule!username_detail(ri!username.username)<>0,false,true),
            style: "PRIMARY",
          ),
          a!buttonWidget(
            label: "update",
            saveInto:(
              a!writeToDataStoreEntity(
                dataStoreEntity: cons!usernameConstant,
                valueToStore:ri!username,           
              ),
            ),
            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
          )
        )
      )
     
    )
    )
    
    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error in rule 'username_detail' at function a!queryLogicalExpression [line 8]: The a!queryFilter function has an invalid value for the "value" parameter. When the value of "operator" is "=" "value" must not be null or empty.

  • a!queryEntity(
      entity: cons!usernameConstant,
      query: a!query(
        pagingInfo: a!pagingInfo(
          startIndex: 1,
          batchSize: 50
        ),
        logicalexpression: a!queryLogicalExpression(
          operator: "AND",
          filters: {
            a!queryFilter(
              field: "username",
              operator: "=",
              value: ri!username
            )
          }
        ),
        aggregation: a!queryAggregation(
          aggregationColumns: {
            a!queryAggregationColumn(
              field: "username",
              isGrouping: true
            ),
            a!queryAggregationColumn(
              field: "username",
              alias: "number",
              aggregationFunction: "COUNT"
            )
          }
        ),
      ),
    ).data

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    Line 15

    validations: {
      if(
        a!queryEntity(
          entity: cons!usernameConstant,
          fetchTotalCount: true,
          query: a!query(
            pagingInfo: a!pagingInfo(
              startIndex: 1,
              batchSize: 1
            ),
            filter: a!queryFilter(
              field: "username",
              operator: "=",
              value: ri!username.username
            )
          )
        ).totalCount > 0,
        "Username exists",
        null
      )
    }

  • "username exists" means it won't do any action, null means it won't prevent it implement action on insert or update delete right?

  • 0
    Certified Lead Developer
    in reply to immortalvirgil

    If the parameter "validate" for a button is set to true, it will perform all validations on the interface before submitting. In case there is any non-null validation it will not submit.

    Check this and filter for "Validation" below "Search Patterns"

    docs.appian.com/.../SAIL_Recipes.html

  • Thanks for your help, but seems lastly could you tell me how to get rid of error of "When the value of "operator" is "=" "value" must not be null or empty." from your validation part give me away? I think the value can't be empty, but i can't throw its error away. Thank you