darrenSP
8 years agoMentor
Get last accepted solution
Is there a way (preferably using V2 API) to get the last accepted solution within the community?
I can get all accepted solutions using:
SELECT solution_data,is_solution FROM messages WHERE is_solution = true
But ORDER BY is not allowed on any column that is returned so I cannot use the time column.
Any ideas?
darrenSP You can get the solution accepted time as nested in solution_data but you can not use nested parameter in order by.
Here you can use a workaround. Use below approach<#assign accepted_solution = rest("2.0","/search?q=" + "SELECT solution_data,is_solution FROM messages WHERE is_solution = true"?url).data.items[0] />
<#assign time = accepted_solution.solution_data.time?long />
<#assign latest_soution_id = accepted_solution.solution_data.message_id />
<#assign solutions_count = rest("2.0","/search?q=" + "SELECT count(*) FROM messages WHERE is_solution = true"?url).data.count />
<#assign solutions = rest("2.0","/search?q=" + "SELECT solution_data,is_solution FROM messages WHERE is_solution = true limit ${solutions_count}"?url).data.items />
<#list solutions as solution>
<#if solution.solution_data.time?long > time >
<#assign time = solution.solution_data.time?long />
<#assign latest_soution_id = solution.solution_data.message_id />
</#if>
</#list>
${latest_soution_id}Hope it would work for you.