Forum Discussion

Natkinson's avatar
Natkinson
Genius
4 years ago

Trying to use occasion_data.status

I have a simple liql query where I'm pulling in all upcoming and ongoing (in progress) events. According to this doc there should be an object for occasion_data.status in the results. It's working within my query "WHERE occasion_data.status IN ('upcoming','ongoing')" but I get a null value if I try to use it in my FreeMarker template (e.g., <#assign eventStatus = listItems.occasion_data.status/>)

Anyone know why? Did they miss adding this? Am I reading the doc wrong? Is my code incorrect somewhere?

  • RyanPi's avatar
    RyanPi
    Khoros Staff

    Hello there,

    This is a great question! I do need a little more context to properly test this on our end.

    Can we see more of the code? For example, how are you making the query within FreeMarker? Are you using the rest context object, liql context object, etc.?

    More information:

    Once I have this information, I can test the method of retrieving data from the rest API against the data being retrieved. That will help us determine where the issue is.

    Here is some more information that might be helpful:

    Thanks so much for your help and patience,

    Ryan

    • Natkinson's avatar
      Natkinson
      Genius

      Excuse my code if it's messy, I'm still learning all the Khoros stuff! ðŸ˜…

      Here's the basic query I'm using, I've stripped out a few things that didn't really pertain to my issue. The real issue is that the query isn't returning the status object, whether I run it here in my code or if I run it in the API browser in Studio

      <#assign currentDate=.now?iso_local>
      <#assign occasionQry="SELECT subject, view_href, occasion_data, images FROM messages WHERE board.id='instructurelive' AND occasion_data.status IN ('upcoming','ongoing')  ORDER BY occasion_data.start_time asc LIMIT 1" />
      <#assign getOccasionData=commonUtils.executeLiQLQuery(occasionQry) />
      <#list getOccasionData as occasionData>
      //Assign some variables from my query here
      </#list>

      All the docs I'm seeing say that if I grab "occasion_data" I should be able to use the status object (but I'm still learning so I could be interpreting that totally wrong).

      What I was trying to do later on with the occasion_data.status object was something like:

      <#if occasionData.status == 'upcoming'>
      //do some stuff for upcoming events here
      <#else>
      //do stuff for ongoing events here
      </#if>

      But that's where I got the null value error as if my query wasn't pulling in the status object. Can we not use status in this way? It clearly is tied to the event since I can pull it in for my WHERE filter but it doesn't come in as an object that I can use elsewhere in FreeMarker

       

  • MattV's avatar
    MattV
    Khoros Staff

    Run the 

    SELECT subject, view_href, occasion_data, images FROM messages WHERE board.id='instructurelive' AND occasion_data.status IN ('upcoming','ongoing')  ORDER BY occasion_data.start_time asc LIMIT 1

     query in the API browser in studio, and see what the data structure looks like. I don't have a good place to test at the moment, but if you're having issues with that, I'd guess that potentially the occasion status isn't in the exact structure you expect.

    • Natkinson's avatar
      Natkinson
      Genius

      That's the problem, it's not in the structure at all. So I'm wondering, is this something buggy in our instance or an oversight in either the API or the docs? Or maybe just something that's not included yet? Here's what I get back from that query:

      {
        "status" : "success",
        "message" : "",
        "http_code" : 200,
        "data" : {
          "type" : "messages",
          "list_item_type" : "message",
          "size" : 1,
          "items" : [ {
            "type" : "message",
            "view_href" : "/t5/test-event/Upcoming-Test-Event/ev-p/7648",
            "subject" : "Upcoming Test Event",
            "occasion_data" : {
              "type" : "occasion_data",
              "start_time" : "2021-07-15T07:00:00.000-07:00",
              "end_time" : "2021-07-15T08:00:00.000-07:00",
              "timezone" : "US/Mountain",
              "location" : "",
              "featured_guests" : {
                "type" : "users",
                "list_item_type" : "user",
                "size" : 0,
                "items" : [ ]
              },
              "rsvp" : {
                "query" : "SELECT * FROM rsvps WHERE message.id = '7648'"
              },
              "pending_invites" : {
                "query" : "SELECT * FROM occasion_invites WHERE message.id = '7648'"
              }
            },
            "images" : {
              "query" : "SELECT * FROM images WHERE messages.id = '7648'"
            }
          } ]
        },
        "metadata" : { }
      }

       

  • MattV's avatar
    MattV
    Khoros Staff

    APIv2 doesn't always return everything, you may need to specifically select it. So instead of SELECT occassion_data try SELECT occasion_data.status

  • SarahD's avatar
    SarahD
    Khoros Staff

    Natkinson 

    If I understand the return object, correctly, I think you just have a misleading loop variable name.

    what is currently:

    <#if occasionData.status == 'upcoming'>
    //do some stuff for upcoming events here
    <#else>
    //do stuff for ongoing events here
    </#if>

     

    Should be:

    <#if occasionData.occasion_data.status == 'upcoming'>
    //do some stuff for upcoming events here
    <#else>
    //do stuff for ongoing events here
    </#if>

     

  • Thanks MattV for the suggestion. I have tried that in the past and tried it just now to be sure. All I get back is this:

    {
      "status" : "success",
      "message" : "",
      "http_code" : 200,
      "data" : {
        "type" : "messages",
        "list_item_type" : "message",
        "size" : 1,
        "items" : [ {
          "type" : "message",
          "occasion_data" : {
            "type" : "occasion_data"
          }
        } ]
      },
      "metadata" : { }
    }

    So I don't think that's the issue here.

    And yes, that was a typo on my part, SarahD although I've tried it both ways and still get it returning as a null value unfortunately.

    Even if my code is written as below, I still get "The following has evaluated to null or missing: ==> occasionData.occasion_data.status"

    <#assign occasionQry="SELECT occasion_data.status FROM messages" />
    <#assign getOccasionData=commonUtils.executeLiQLQuery(occasionQry) />
    <#list getOccasionData as occasionData>
    <#assign eventStatus=occasionData.occasion_data.status />
    ${eventStatus}
    </#list>

     

    • MattV's avatar
      MattV
      Khoros Staff
      I tested this on my side, and seeing the same results (APIv2 not returning
      status), which I would consider to be unexpected.

      Honestly sounds like it may be a bug to me.
      • Natkinson's avatar
        Natkinson
        Genius

        MattV would you suggest filing a ticket with support to report this as a bug? Or what's the best course of action for reporting issues like this?

  • MattV 

    was it fixed?

    I ran the API code and don't get occasion_data.status results.

    • Natkinson's avatar
      Natkinson
      Genius

      irach15 no it hasn't been resolved. I put in a support ticket and engineering said it's working as intended, that 'status' can be used as a constraint but can't be selected or returned as part of the query. However, I also requested back in July that they update their LiQL dev docs to note this and this still hasn't been updated, it still shows that 'status' is a valid selectable field for this collection.

      • RyanPi's avatar
        RyanPi
        Khoros Staff

        It appears that the changes to the documentation were made and reverted during a version update. I have removed status as a selectable field. My apologies for the oversight.