Forum Discussion

bhupen's avatar
bhupen
Advisor
10 years ago

Get Author name

Hi guyz,

 

iam not able to print author name although subject is printed fine:

<#assign users = rest("2.0","/search?q=" + "SELECT id, login FROM users WHERE roles.name='Administrator'"?url) />
    <#if users??>
        <#assign whereclause = ""/>
            <#list users.data.items as user>
                <#assign whereclause = whereclause + "'" + user.id + "'" />
                <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
            </#list>
            <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />
            <#list messages.data.items as recent >
                <#if recent??>

           <a href="${recent.view_href}">${recent.author.login}</a>
                <a href="${recent.view_href}">${recent.subject}</a><br/>
                </#if>
            </#list>
    </#if>

  • bhupen you need the author.login in your SELECT statement otherwise the value won't be returned ...

     

    <#assign users = rest("2.0","/search?q=" + "SELECT id, login FROM users WHERE roles.name='Administrator'"?url) />
        <#if users??>
            <#assign whereclause = ""/>
                <#list users.data.items as user>
                    <#assign whereclause = whereclause + "'" + user.id + "'" />
                    <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
                </#list>
                <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id,author.login FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />
                <#list messages.data.items as recent >
                    <#if recent??>
    
               <a href="${recent.view_href}">${recent.author.login}</a>
                    <a href="${recent.view_href}">${recent.subject}</a><br/>
                    </#if>
                </#list>
        </#if>

     

2 Replies

  • OlivierS's avatar
    OlivierS
    Lithium Alumni (Retired)
    10 years ago

    bhupen you need the author.login in your SELECT statement otherwise the value won't be returned ...

     

    <#assign users = rest("2.0","/search?q=" + "SELECT id, login FROM users WHERE roles.name='Administrator'"?url) />
        <#if users??>
            <#assign whereclause = ""/>
                <#list users.data.items as user>
                    <#assign whereclause = whereclause + "'" + user.id + "'" />
                    <#if user_has_next><#assign whereclause = whereclause + "," /></#if>
                </#list>
                <#assign messages = rest("2.0","/search?q=" + "SELECT subject, view_href, post_time_friendly, board.id, author.id,author.login FROM messages WHERE author.id IN (${whereclause}) ORDER BY post_time DESC LIMIT 5"?url) />
                <#list messages.data.items as recent >
                    <#if recent??>
    
               <a href="${recent.view_href}">${recent.author.login}</a>
                    <a href="${recent.view_href}">${recent.subject}</a><br/>
                    </#if>
                </#list>
        </#if>