Widget API - How to test for calendar not found?

Here is the issue in as few lines of widget code as possible.

#set($calendar = false)
#set($calendar = $calendar_v1_calendars.Show(123456789))
$calendar

This always returns "Telligent.Evolution.Extensions.Calendar.Extensibility.Api.Entities.Version1.Calendar", no matter what value you pass to $calendar_v1_calendars.Show().  The result I was expecting was False, since there is no calendar with that Id.

My expectation is based on the code save.vm file that is part of the OOTB "Event Calendar - Add/Edit Event", shown below.  The problem is that given the results I found above, "if(!calendar)" will always fail (meaning the calendar was found), even if it wasn't... because $calendar_v1_calendars.Show()) always returns a result.

$core_v2_page.SetContentType('application/json')

#set($calendarId = $core_v2_utility.ParseInt($core_v2_page.GetFormValue('calendarId')))
#set($calendar = false)
#set($calendar = $calendar_v1_calendars.Show($calendarId))
#if(!$calendar)
    $core_v2_page.SendJsonError('The specified calendar not be retrieved')
#end

As far as I can tell, either...

  • $calendar_v1_calendars.Show() has a bug, and should be returning null when the Calendar can't be found.
  • Or save.vm has a bug and isn't properly checking to see if the Calendar exists.
  • Or I am missing something.

I did find a workaround...

#set($calendar = $calendar_v1_calendars.Show(123456789))
#if(!$calendar.Id)
    #set($calendar = false)
#end
$calendar

It appears that when the Calendar can't be found, it returns an empty Calendar object.  So you can just check the $calendar.Id to see if is populated.

I guess I answered my own question, but I'm not sure if my solution is adequate.  I was hoping that someone with more experience with the Telligent widget API would be able to validate my findings and workaround.

Thanks.

Parents Reply Children
No Data