Required dropdown to show date in MMM-DD format

Hi All,

I got one change request, to show the date in "MMM-DD" format for the current calendar year, I think this can be achieved by concatenating two dropdowns (when user selects month in the first dropdown and  second drop down should show days in the months) and  I need to write some code to do that.

Can anyone please guide me in achieving the same? Thanks in advance.

We are using Appian 23.3 version. 

Thanks

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi  ,

    Since you said it is current calendar year, You can use below code. But if you want year also to be dynamic, then create another dropdown for year also.

    if you have the date already then use text(date,"mmm-dd")

    a!localVariables(
      local!months:{"January","February","March","April","May","June","July","August","September","October","November","December"},
      local!monthSaved,
      local!daySaved,
      {
        a!dropdownField(
          label: "Month",
          placeholder: "Select Month",
          choiceLabels: local!months,
          choiceValues: enumerate(length(local!months))+1,
          value: local!monthSaved,
          saveInto:{
            local!monthSaved,
            a!save(local!daySaved,null)
          } 
        ),
        a!dropdownField(
          label: "Day",
          placeholder: "Select Day",
          choiceLabels:if(
            a!isNullOrEmpty(local!monthSaved),{},
            enumerate(daysinmonth(local!monthSaved,year(today())))+1
          ),
          choiceValues: if(
            a!isNullOrEmpty(local!monthSaved),{},
            enumerate(daysinmonth(local!monthSaved,year(today())))+1
          ),
          value: local!daySaved,
          saveInto:{
            local!daySaved
          } 
        ),
        a!richTextDisplayField(
          label: "Saved Date",
          labelPosition: "JUSTIFIED",
          value: {
            a!richTextItem(
              text: text(date(year(today()),local!monthSaved,local!daySaved),"mmm-dd")
            )
          },
          showWhen: and(a!isNotNullOrEmpty(local!monthSaved),a!isNotNullOrEmpty(local!daySaved))
        )
      }
    )

Reply
  • 0
    Certified Senior Developer

    Hi  ,

    Since you said it is current calendar year, You can use below code. But if you want year also to be dynamic, then create another dropdown for year also.

    if you have the date already then use text(date,"mmm-dd")

    a!localVariables(
      local!months:{"January","February","March","April","May","June","July","August","September","October","November","December"},
      local!monthSaved,
      local!daySaved,
      {
        a!dropdownField(
          label: "Month",
          placeholder: "Select Month",
          choiceLabels: local!months,
          choiceValues: enumerate(length(local!months))+1,
          value: local!monthSaved,
          saveInto:{
            local!monthSaved,
            a!save(local!daySaved,null)
          } 
        ),
        a!dropdownField(
          label: "Day",
          placeholder: "Select Day",
          choiceLabels:if(
            a!isNullOrEmpty(local!monthSaved),{},
            enumerate(daysinmonth(local!monthSaved,year(today())))+1
          ),
          choiceValues: if(
            a!isNullOrEmpty(local!monthSaved),{},
            enumerate(daysinmonth(local!monthSaved,year(today())))+1
          ),
          value: local!daySaved,
          saveInto:{
            local!daySaved
          } 
        ),
        a!richTextDisplayField(
          label: "Saved Date",
          labelPosition: "JUSTIFIED",
          value: {
            a!richTextItem(
              text: text(date(year(today()),local!monthSaved,local!daySaved),"mmm-dd")
            )
          },
          showWhen: and(a!isNotNullOrEmpty(local!monthSaved),a!isNotNullOrEmpty(local!daySaved))
        )
      }
    )

Children