Creating Calendar for Timesheet

Hi,

I need to create an interface for timesheet entry.  In the interface when I select the month and year the calendar for that month should be displayed in a grid with days (1, 2 ,3 etc) as links so that I can click the link to enter the number of hours worked on that day.  How can I acheive this?  I need to create this interface in 18.1 version.  Thanks in advance.

  Discussion posts and replies are publicly visible

  • Hi Brinda,

    for this requirement when user selects the month and the year you can get the starting day of the month by weekday function which returns the weekday for that day and u can form the list of dictionary with key value pair as {Monday:"",Tuesday:1,Wednesday:2,.....}.
    now you can display it in the grid and for each date give a link and display a section to enter the no. of hours worked.and store this data.
    Later on you can save this in DB.

    Regards,
    Rajat Saxena
  • 0
    Certified Lead Developer
    Hi,

    First you need to find out the no. of days in your month. You can do that by using daysinmonth() funtion.
    After you have the no. of days in the selected month, use the function weekday() to create a dictionary object for all the dates that fall under a particular day..for that month..for eg.{monday:{1,7,14},tuesday{2,8,15}..so on}.
    Once you have the dictionary objects, use that in a pagingGrid and provide links that will call a section to enter the no. of hours.
    Your pagingGrid columns will be monday,tuesday,,,,,upto sunday and the values will be the ones from the dictionary object.
  • 0
    Certified Senior Developer
    in reply to Aditya

    Can you tell me the code for this asap

  • I've avoided using plugins, CDTs and referencing other rules but this works Slight smile

    a!localVariables(
      local!blankWeekDictionary: {
        monday: {},
        tuesday: {},
        wednesday: {},
        thursday: {},
        friday: {},
        saturday: {},
        sunday: {}
      },
      local!today: todate(local(now())),
      local!month: month(local!today),
      local!year: year(local!today),
      local!daysInMonth: daysinmonth(
        local!month,
        local!year
      ),
      local!unsortedMonthData: a!forEach(
        items: 1 + enumerate(local!daysInMonth),
        expression: a!localVariables(
          local!date: date(
            local!year,
            local!month,
            fv!item
          ),
          {
            date: local!date,
            dayNumberInMonth: fv!item,
            dayNumberInWeek: weekday(
              local!date,
              2
            ),
            dayName: text(local!date, "dddd")
          }
        )
      ),
      local!sortedMonthData: a!forEach(
        items: 1 + enumerate(7) /*There are 7 days in a week*/,
        expression: a!localVariables(
          local!matchingDayNumberInWeekDetails: index(
            local!unsortedMonthData,
            wherecontains(
              fv!item,
              tointeger(
                index(
                  local!unsortedMonthData,
                  "dayNumberInWeek",
                  {}
                )
              )
            ),
            {}
          ),
          local!matchingDayNumberInMonth: index(
            local!matchingDayNumberInWeekDetails,
            "dayNumberInMonth",
            {}
          ),
          local!matchingDayNumberInMonth
        )
      ),
      reduce(
        a!update,
        local!blankWeekDictionary,
        merge(
          {
            "monday",
            "tuesday",
            "wednesday",
            "thursday",
            "friday",
            "saturday",
            "sunday"
          },
          local!sortedMonthData
        )
      )
    )

  • 0
    Certified Senior Developer
    in reply to ajhick

    hey I need your help.

  • 0
    Certified Senior Developer
    in reply to shikhab0003

    Below is my code . Using this expression i want to display calendar . I am facing problem in displaying .

     If you can correct my code ...I will be very thank full . 

    a!localVariables(
    local!s:weekday(date(ri!y,ri!m,1),1),
    local!t:daysinmonth(ri!m,ri!y),
    choose(local!s,
    if(local!s=1,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Sunday",
    {
    sun:if(fv!item+1<local!t+1,fv!item+1,{}),
    mon:if(fv!item+2<local!t+1,fv!item+2,{}),
    tues:if(fv!item+3<local!t+1,fv!item+3,{}),
    wed:if(fv!item+4<local!t+1,fv!item+4,{}),
    thurs:if(fv!item+5<local!t+1,fv!item+5,{}),
    fri:if(fv!item+6<local!t+1,fv!item+6,{}),
    sat:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=2,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Monday",
    {
    mon:if(fv!item+1<local!t+1,fv!item+1,{}),
    tues:if(fv!item+2<local!t+1,fv!item+2,{}),
    wed:if(fv!item+3<local!t+1,fv!item+3,{}),
    thurs:if(fv!item+4<local!t+1,fv!item+4,{}),
    fri:if(fv!item+5<local!t+1,fv!item+5,{}),
    sat:if(fv!item+6<local!t+1,fv!item+6,{}),
    sun:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=3,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Tuesday",
    {
    tues:if(fv!item+1<local!t+1,fv!item+1,{}),
    wed:if(fv!item+2<local!t+1,fv!item+2,{}),
    thurs:if(fv!item+3<local!t+1,fv!item+3,{}),
    fri:if(fv!item+4<local!t+1,fv!item+4,{}),
    sat:if(fv!item+5<local!t+1,fv!item+5,{}),
    sun:if(fv!item+6<local!t+1,fv!item+6,{}),
    mon:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=4,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Wednesday",
    {
    wed:if(fv!item+1<local!t+1,fv!item+1,{}),
    thurs:if(fv!item+2<local!t+1,fv!item+2,{}),
    fri:if(fv!item+3<local!t+1,fv!item+3,{}),
    sat:if(fv!item+4<local!t+1,fv!item+4,{}),
    sun:if(fv!item+5<local!t+1,fv!item+5,{}),
    mon:if(fv!item+6<local!t+1,fv!item+6,{}),
    tues:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=5,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Thursday",
    {
    thurs:if(fv!item+1<local!t+1,fv!item+1,{}),
    fri:if(fv!item+2<local!t+1,fv!item+2,{}),
    sat:if(fv!item+3<local!t+1,fv!item+3,{}),
    sun:if(fv!item+4<local!t+1,fv!item+4,{}),
    mon:if(fv!item+5<local!t+1,fv!item+5,{}),
    tues:if(fv!item+6<local!t+1,fv!item+6,{}),
    wed:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=6,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Friday",
    {
    fri:if(fv!item+1<local!t+1,fv!item+1,{}),
    sat:if(fv!item+2<local!t+1,fv!item+2,{}),
    sun:if(fv!item+3<local!t+1,fv!item+3,{}),
    mon:if(fv!item+4<local!t+1,fv!item+4,{}),
    tues:if(fv!item+5<local!t+1,fv!item+5,{}),
    wed:if(fv!item+6<local!t+1,fv!item+6,{}),
    thurs:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=7,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Saturday",
    {
    sat:if(fv!item+1<local!t+1,fv!item+1,{}),
    sun:if(fv!item+2<local!t+1,fv!item+2,{}),
    mon:if(fv!item+3<local!t+1,fv!item+3,{}),
    tues:if(fv!item+4<local!t+1,fv!item+4,{}),
    wed:if(fv!item+5<local!t+1,fv!item+5,{}),
    thurs:if(fv!item+6<local!t+1,fv!item+6,{}),
    fri:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),))

  • 0
    Certified Senior Developer
    in reply to ajhick

     According to my code dates are displaying like this. I am not able to improve my code . how can i? 

    a!localVariables(
    local!s:weekday(date(ri!y,ri!m,1),1),
    local!t:daysinmonth(ri!m,ri!y),
    choose(local!s,
    if(local!s=1,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Sunday",
    {
    sun:if(fv!item+1<local!t+1,fv!item+1,{}),
    mon:if(fv!item+2<local!t+1,fv!item+2,{}),
    tues:if(fv!item+3<local!t+1,fv!item+3,{}),
    wed:if(fv!item+4<local!t+1,fv!item+4,{}),
    thurs:if(fv!item+5<local!t+1,fv!item+5,{}),
    fri:if(fv!item+6<local!t+1,fv!item+6,{}),
    sat:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=2,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Monday",
    {
    mon:if(fv!item+1<local!t+1,fv!item+1,{}),
    tues:if(fv!item+2<local!t+1,fv!item+2,{}),
    wed:if(fv!item+3<local!t+1,fv!item+3,{}),
    thurs:if(fv!item+4<local!t+1,fv!item+4,{}),
    fri:if(fv!item+5<local!t+1,fv!item+5,{}),
    sat:if(fv!item+6<local!t+1,fv!item+6,{}),
    sun:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=3,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Tuesday",
    {
    tues:if(fv!item+1<local!t+1,fv!item+1,{}),
    wed:if(fv!item+2<local!t+1,fv!item+2,{}),
    thurs:if(fv!item+3<local!t+1,fv!item+3,{}),
    fri:if(fv!item+4<local!t+1,fv!item+4,{}),
    sat:if(fv!item+5<local!t+1,fv!item+5,{}),
    sun:if(fv!item+6<local!t+1,fv!item+6,{}),
    mon:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=4,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Wednesday",
    {
    wed:if(fv!item+1<local!t+1,fv!item+1,{}),
    thurs:if(fv!item+2<local!t+1,fv!item+2,{}),
    fri:if(fv!item+3<local!t+1,fv!item+3,{}),
    sat:if(fv!item+4<local!t+1,fv!item+4,{}),
    sun:if(fv!item+5<local!t+1,fv!item+5,{}),
    mon:if(fv!item+6<local!t+1,fv!item+6,{}),
    tues:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=5,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Thursday",
    {
    thurs:if(fv!item+1<local!t+1,fv!item+1,{}),
    fri:if(fv!item+2<local!t+1,fv!item+2,{}),
    sat:if(fv!item+3<local!t+1,fv!item+3,{}),
    sun:if(fv!item+4<local!t+1,fv!item+4,{}),
    mon:if(fv!item+5<local!t+1,fv!item+5,{}),
    tues:if(fv!item+6<local!t+1,fv!item+6,{}),
    wed:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),
    if(local!s=6,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Friday",
    {
    fri:if(fv!item+1<local!t+1,fv!item+1,{}),
    sat:if(fv!item+2<local!t+1,fv!item+2,{}),
    sun:if(fv!item+3<local!t+1,fv!item+3,{}),
    mon:if(fv!item+4<local!t+1,fv!item+4,{}),
    tues:if(fv!item+5<local!t+1,fv!item+5,{}),
    wed:if(fv!item+6<local!t+1,fv!item+6,{}),
    thurs:if(fv!item+7<local!t+1,fv!item+7,{})
    }
    ,{})}
    ),{}),
    if(local!s=7,
    a!forEach(
    items:enumerate(daysinmonth(ri!m,ri!y)),
    expression:{if(text(date(ri!y,ri!m,fv!item+1),"dddd")="Saturday",
    {
    sat:if(fv!item+1<local!t+1,fv!item+1,{}),
    sun:if(fv!item+2<local!t+1,fv!item+2,{}),
    mon:if(fv!item+3<local!t+1,fv!item+3,{}),
    tues:if(fv!item+4<local!t+1,fv!item+4,{}),
    wed:if(fv!item+5<local!t+1,fv!item+5,{}),
    thurs:if(fv!item+6<local!t+1,fv!item+6,{}),
    fri:if(fv!item+7<local!t+1,fv!item+7,{}),
    }
    ,{})}
    ),{}),))