Skip to main content
September 1, 2021
Solved

How to make the active column from database can't be null switch to be allowed?

  • September 1, 2021
  • 20 replies
  • 0 views

a!localVariables(
  
  
   
  local!allRole:rule!KONE_Development_ROLE(),
  local!allLanguage:rule!KONE_Development_LANGUAGE(),
  local!allBranch:rule!KONE_Development_BRANCH(),
  local!allRegion:rule!KONE_Development_REGION(),
 
    

  a!formLayout(
    contents: {
      a!textField(
        label: "Username",
        value: {ri!userinputsheet.kone_user_name},
        saveInto: {
          a!save(target:ri!userinputsheet.kone_user_name,
                 value:save!value),
          a!save(target:ri!userrole.NAME,
                 value:save!value),
         },
        required: true
      ),
      a!textField(
        label: "firstName",
        value: {ri!userinputsheet.FIRST_NAME},
        saveInto: {ri!userinputsheet.FIRST_NAME},
        required: true
      ),
      a!textField(
        label: "LastName",
        value: {ri!userinputsheet.LAST_NAME},
        saveInto: {ri!userinputsheet.LAST_NAME},
        required: true
      ),
      a!textField(
        label: "Email",
        value: {ri!userinputsheet.Email},
        saveInto: {
          a!save(target:ri!userinputsheet.Email,
                 value:save!value),
          a!save(target:ri!userrole.EMAIL,value:save!value),
        },
        required: true
      ),
      a!dropdownField(
        label:"Role",
        placeholder:"---please fill your Role---",
        choiceLabels:reject(fn!isnull,local!allRole),
        choiceValues:reject(fn!isnull,local!allRole),
        value:ri!userinputsheet.Role,
        saveInto:{
        a!save(target:ri!userinputsheet.Role,value:save!value),
        a!save(
          target:ri!userrole.ROLE_ID,
          value: a!forEach
        (items:rule!KONE_Development_Role_RoleId(),
        expression:if(fv!item.Role=ri!userinputsheet.Role,fv!item.Role_Id,{})        
        )),
        a!save(target:ri!userrole.PHASE_ID,
        value:a!forEach
        (items:rule!KONE_Development_Role_RoleId(),
        expression:if(fv!item.Role=ri!userinputsheet.Role,fv!item.Role_Id,{})        
        ))
        },
        required:true       
      ),
      a!dropdownField(
        label:"Branch",
        placeholder:"---please fill your Branch---",
        choiceLabels:reject(fn!isnull,local!allBranch),
        choiceValues:reject(fn!isnull,local!allBranch),
        value:ri!userinputsheet.Branch,
        saveInto:{
        a!save(target:ri!userinputsheet.Branch,value:save!value),
        a!save(target:ri!userrole.BRANCH,value:save!value),
        a!save(target:ri!userrole.BRANCH_ID,
        value:a!forEach
        (items:rule!KONE_Development_Branch_BranchId(),
        expression:if(fv!item.Branch=ri!userinputsheet.Branch,fv!item.Branch_Id,{})        
        ))
        },
        required:true       
      ),
      a!dropdownField(
        label:"Region",
        placeholder:"---please fill your Region---",
        choiceLabels:reject(fn!isnull,local!allRegion),
        choiceValues:reject(fn!isnull,local!allRegion),
        value:ri!userinputsheet.Region,
        saveInto:{
        a!save(target:ri!userinputsheet.Region,value:save!value),
        a!save(target:ri!userrole.REGION,value:save!value),
        a!save(target:ri!userrole.REGION_ID,
        value:a!forEach
        (items:rule!KONE_Development_Region_RegionId(),
        expression:if(fv!item.Region=ri!userinputsheet.Region,fv!item.Region_Id,{})        
        ))
        },
        required:true       
      ),
      a!dropdownField(
        label:"Manager_Role",
        placeholder:"---please fill your Role---",
        choiceLabels:reject(fn!isnull,local!allRole),
        choiceValues:reject(fn!isnull,local!allRole),
        value:ri!userinputsheet.Manager_role,
        saveInto:{
          a!save(target:ri!userinputsheet.Manager_role,value:save!value),
        },
        required:true     
      ),
      a!dropdownField(
        label:"Language",
        placeholder:"---please fill your Language---",
        choiceLabels:reject(fn!isnull,local!allLanguage),
        choiceValues:reject(fn!isnull,local!allLanguage),
        value:ri!userinputsheet.Language,
        saveInto:{
        a!save(target:ri!userinputsheet.Language,value:save!value),
        a!save(target:ri!userrole.LANGUAGE_ID,
        value:a!forEach
        (items:rule!KONE_Development_Language_LanguageId(),
        expression:if(fv!item.Language=ri!userinputsheet.Language,fv!item.Language_Id,{})        
        ))
        },
        required:true       
      ),
      a!textField(
        label: "CELevel",
        value: {ri!userinputsheet.CE_LEVEL},
        saveInto: {
          a!save(target:ri!userinputsheet.CE_LEVEL,value:save!value),
          a!save(target:ri!userrole.LEVEL,value:save!value)
        },
        required: true
      ),
      a!textField(
        label: "Telephone Number",
        value: {ri!userinputsheet.Telephone_number},
        saveInto: {
          a!save(target:ri!userinputsheet.Telephone_number,value:save!value),
          a!save(target:ri!userrole.TELEPHONE_NUMBER,value:save!value)
        },
        required: true
      ),
      a!textField(
        label: "Exceptional Case Library View Right",
        value: {ri!userinputsheet.Exceptional_case_library_view_right},
        saveInto: {
          a!save(target:ri!userinputsheet.Exceptional_case_library_view_right,value:save!value),
          a!save(target:ri!userrole.IS_EXCEPTION,value:save!value),
        },
        required: true
      )
      
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          saveInto:(
            a!writeToDataStoreEntity(
              dataStoreEntity: {cons!KONE_Development_userrole_Constant,cons!KONE_Development_userinputsheet_Constant},
              valueToStore:{ri!userrole,ri!userinputsheet}          
            ),
          ),
          submit: true,
          style: "PRIMARY"
        )
       
      }
      
    )
  )
)

error is: Interface Definition: Expression evaluation error: An error occurred while executing a smart service: An error occurred while trying to write to the entity "KONE_Development_userrole" [id=8a2e408a-8d63-40b5-8b0b-ac820966b9ea@16406, type=USER_ROLE (id=3178)] (data store: KONE_User_Development_Database). Details: org.hibernate.exception.ConstraintViolationException: could not insert: [USERROLEDT2804]: java.sql.SQLIntegrityConstraintViolationException: (conn=65245) Column 'ACTIVE' cannot be null: org.mariadb.jdbc.internal.util.exceptions.MariaDbSqlException: Column 'ACTIVE' cannot be null: java.sql.SQLException: Column 'ACTIVE' cannot be null Data: TypedValue[it=3179,v={{<null>,immortalvirgil,luzhe.wang@accenture.com,,131,131,CNZZ,SO,,,,,41,6,<null>,<null>,<null>,<null>,,,<null>,6,8613478478682,0,},{<null>,,luzhe.wang@accenture.com,HQ CSE Manager,<null>,<null>,CNZZ,SO,,,,HQ SC CSE Engineer,<null>,<null>,<null>,<null>,<null>,<null>,,,<null>,<null>,8613478478682,<null>,}}]

how can i make the active column can be null? Thank you so much

    Best answer by mikes0011

    You need to have one of your existing field's saveInto parameters (it doesn't really matter which one, as long as it's one the user has to fill out), set a value for all required columns such as "isActive".

    Additionally I don't believe a!writeToDataStoreEntity will accept an array of DSE constants like in your original posted code, but I think some other responders have already addressed this (i assume you should be able to use a!writeToMultipleDataStoreEntities() instead).

    20 replies

    September 1, 2021

    Can you share your CDT?

    September 1, 2021

    <xsd:element name="test" nillable="true" type="xsd:boolean" /> ALso check if the XSD value is nullable set to true

    September 1, 2021

    what if i want write code from interface?

    mikes0011
    mikes0011Answer
    Brainy
    September 1, 2021

    You need to have one of your existing field's saveInto parameters (it doesn't really matter which one, as long as it's one the user has to fill out), set a value for all required columns such as "isActive".

    Additionally I don't believe a!writeToDataStoreEntity will accept an array of DSE constants like in your original posted code, but I think some other responders have already addressed this (i assume you should be able to use a!writeToMultipleDataStoreEntities() instead).

    The Expression Guru
    September 2, 2021

    Do you know how to leave the textfield back to blank after click buttons?

    mikes0011
    Brainy
    September 2, 2021

    in the "onSuccess" parameter of your WriteToDataStoreEntity rule (whichever version you use should make no difference), place additional a!save() statements that clear out the data again.  for example, "a!save(ri!myCdt, {})" to save an empty data set back into ri!myCdt (and only after the DB write has completed).

    The Expression Guru