Date compare is null

Hi, I want to have a ri!startDate, I will use the a!isNotNull function to display some warning message if the ri!startDate is null else will retrieve the weekday(ri!startDate)

but I keep encountering the error message such as Cannot sub incompatible operands of type Date and type Text.

below here is my code for the interface

a!localVariables(
  local!weeknum:if(a!isNotNullOrEmpty(ri!startDate),weeknum(ri!startDate),{}),
  local!day:if(a!isNotNullOrEmpty(ri!startDate),day(ri!startDate),{}),
  local!month:if(a!isNotNullOrEmpty(ri!startDate),month(ri!startDate),{}),
  local!year:if(a!isNotNullOrEmpty(ri!startDate),year(ri!startDate),{}),
  local!dayofWeek:if(ri!startDate=null(),"Please Select a Date ", weekday(ri!startDate)-1),
  local!startWeekDay:if(local!dayofWeek<>1,ri!startDate-local!dayofWeek+1,{}),
  local!endWeekDay:local!startWeekDay+4,
  local!monday:local!startWeekDay,
  local!tuesday:local!startWeekDay+1,
  local!wednesday:local!startWeekDay+2,
  local!thursday:local!startWeekDay+3,
  local!friday:local!startWeekDay+4,
  
  
a!formLayout(
  label: "Form",
  contents: {
    a!sectionLayout(
      contents: {
        a!dateField(
          label: "Start Date",
          labelPosition: "ABOVE",
          value:today(),
          saveInto: ri!startDate,
          validations: {}
        )
      }
    ),
    a!integerField(
      label: local!monday,
      labelPosition: "JUSTIFIED",
      saveInto: {},
      refreshAfter: "UNFOCUS",
      validations: {}
    ),
    a!integerField(
      label: local!tuesday,
      labelPosition: "JUSTIFIED",
      saveInto: {},
      refreshAfter: "UNFOCUS",
      validations: {}
    )

  },
  buttons: a!buttonLayout(
    primaryButtons: {
      a!buttonWidget(
        label: "Submit",
        submit: true,
        style: "PRIMARY"
      )
    },
    secondaryButtons: {
      a!buttonWidget(
        label: "Cancel",
        value: true,
        saveInto: ri!cancel,
        submit: true,
        style: "NORMAL",
        validate: false
      )
    }
  )
)
)

  Discussion posts and replies are publicly visible

Parents
  • Hello 

    Below is the fixed code

    a!localVariables(
      local!weeknum: if(
        a!isNotNullOrEmpty(ri!startDate),
        weeknum(ri!startDate),
        {}
      ),
      local!day: if(
        a!isNotNullOrEmpty(ri!startDate),
        day(ri!startDate),
        {}
      ),
      local!month: if(
        a!isNotNullOrEmpty(ri!startDate),
        month(ri!startDate),
        {}
      ),
      local!year: if(
        a!isNotNullOrEmpty(ri!startDate),
        year(ri!startDate),
        {}
      ),
      local!dayofWeek: if(
        isnull(ri!startDate),
        "Please Select a Date ",
        weekday(ri!startDate) - 1
      ),
      local!startWeekDay: if(
        isnull(ri!startDate),
        0,
        if(
          local!dayofWeek <> 1,
          ri!startDate - local!dayofWeek + 1,
          {}
        )
      ),
      local!endWeekDay: local!startWeekDay + 4,
      local!monday: local!startWeekDay,
      local!tuesday: local!startWeekDay + 1,
      local!wednesday: local!startWeekDay + 2,
      local!thursday: local!startWeekDay + 3,
      local!friday: local!startWeekDay + 4,
      a!formLayout(
        label: "Form",
        contents: {
          a!sectionLayout(
            contents: {
              a!dateField(
                label: "Start Date",
                labelPosition: "ABOVE",
                value: today(),
                saveInto: ri!startDate,
                validations: {}
              )
            }
          ),
          a!integerField(
            label: local!monday,
            labelPosition: "JUSTIFIED",
            saveInto: {},
            refreshAfter: "UNFOCUS",
            validations: {}
          ),
          a!integerField(
            label: local!tuesday,
            labelPosition: "JUSTIFIED",
            saveInto: {},
            refreshAfter: "UNFOCUS",
            validations: {}
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              submit: true,
              style: "PRIMARY"
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: ri!cancel,
              submit: true,
              style: "NORMAL",
              validate: false
            )
          }
        )
      )
    )

    Changes I have done

    1.  local!dayofWeek - cannot comapre ri!startDate with null() as the type of ri!startDate is Date, hence we need to use isNull() function to check if it is null.

    2. local!startWeekDay - if ri!startDate is null we local!dayofWeek holds a text value hence no mathematical operations can be done on it, so I have added a null check and set the value to zero if ri!startDate is null.

    Hope this helps.

Reply
  • Hello 

    Below is the fixed code

    a!localVariables(
      local!weeknum: if(
        a!isNotNullOrEmpty(ri!startDate),
        weeknum(ri!startDate),
        {}
      ),
      local!day: if(
        a!isNotNullOrEmpty(ri!startDate),
        day(ri!startDate),
        {}
      ),
      local!month: if(
        a!isNotNullOrEmpty(ri!startDate),
        month(ri!startDate),
        {}
      ),
      local!year: if(
        a!isNotNullOrEmpty(ri!startDate),
        year(ri!startDate),
        {}
      ),
      local!dayofWeek: if(
        isnull(ri!startDate),
        "Please Select a Date ",
        weekday(ri!startDate) - 1
      ),
      local!startWeekDay: if(
        isnull(ri!startDate),
        0,
        if(
          local!dayofWeek <> 1,
          ri!startDate - local!dayofWeek + 1,
          {}
        )
      ),
      local!endWeekDay: local!startWeekDay + 4,
      local!monday: local!startWeekDay,
      local!tuesday: local!startWeekDay + 1,
      local!wednesday: local!startWeekDay + 2,
      local!thursday: local!startWeekDay + 3,
      local!friday: local!startWeekDay + 4,
      a!formLayout(
        label: "Form",
        contents: {
          a!sectionLayout(
            contents: {
              a!dateField(
                label: "Start Date",
                labelPosition: "ABOVE",
                value: today(),
                saveInto: ri!startDate,
                validations: {}
              )
            }
          ),
          a!integerField(
            label: local!monday,
            labelPosition: "JUSTIFIED",
            saveInto: {},
            refreshAfter: "UNFOCUS",
            validations: {}
          ),
          a!integerField(
            label: local!tuesday,
            labelPosition: "JUSTIFIED",
            saveInto: {},
            refreshAfter: "UNFOCUS",
            validations: {}
          )
        },
        buttons: a!buttonLayout(
          primaryButtons: {
            a!buttonWidget(
              label: "Submit",
              submit: true,
              style: "PRIMARY"
            )
          },
          secondaryButtons: {
            a!buttonWidget(
              label: "Cancel",
              value: true,
              saveInto: ri!cancel,
              submit: true,
              style: "NORMAL",
              validate: false
            )
          }
        )
      )
    )

    Changes I have done

    1.  local!dayofWeek - cannot comapre ri!startDate with null() as the type of ri!startDate is Date, hence we need to use isNull() function to check if it is null.

    2. local!startWeekDay - if ri!startDate is null we local!dayofWeek holds a text value hence no mathematical operations can be done on it, so I have added a null check and set the value to zero if ri!startDate is null.

    Hope this helps.

Children