Reverse sort order of notes in Agent ticket view

  • 16 June 2016
  • 8 replies
  • 137 views


This was adapted from the Freshdesk plug for reversing the sort order for the customer portal.


<script type="text/javascript">
jQuery(document).ready(function(){
var con = document.getElementById('all_notes');
var els = Array.prototype.slice.call(con.childNodes);
for (var i = els.length -1; i>=0; i--) {
con.appendChild(els[i]);
}
})
</script>
</style>

 



This topic has been closed for comments

8 replies


Note: it still scrolls to the bottom automatically, trying to fix that.



I just realized this breaks a bit when FD condenses updates and adds the "Expand" link and graphic.  



I was able to move the "Expand" thing but when you click it it prepends the hidden rows to the top automatically.  Can't figure out how to work around this yet.


Userlevel 4
Badge +12

Scott,



We already have a custom app for this case . Hope this helps!




This will display the ticket replies in chronological order with the latest activity at the top. 




<div id="reverse_ticket_replies_order"></div>


<script type="text/javascript">


 


  jQuery('#reverse_ticket_replies_order').closest('.widget').removeClass('widget');


  jQuery(document).on("ticket_view_loaded",function(event,data){


    jQuery('.redactor').insertAfter('#original_request');


  });


 


   function changeOrder(){


    var ID = [];


    jQuery('#' + id_value).find(".conversation").each(function(){


      ID.push(jQuery(this).attr('data-timestamp'));


    });


    ID = ID.sort().reverse();


    jQuery(ID).each(function(i,item){


  jQuery('#' + id_value).append(jQuery('[data-timestamp=' + item + ']'));


    });


  }


 


  function reorderNotes(){


   if(jQuery('#all_notes').length)


    {


      id_value = "all_notes";


      changeOrder();


    }


    else


    {


      id_value = "all_activities";


      changeOrder();


    }


  }


 


  jQuery('#Pagearea').ajaxComplete(function(){


    reorderNotes();


  });


</script>






Regards,


Aravind.S



Thanks, that works fairly well.  Couple of issues:




1. Moving the reply/add note section up breaks the UI (gray line down the side)


2. The "expand" indicator for more comments is in the wrong order, it is still at the top, should be at the bottom





Made some modifications:


 


<div id="reverse_ticket_replies_order"></div>
<script type="text/javascript">

jQuery('#reverse_ticket_replies_order').closest('.widget').removeClass('widget');
jQuery(document).on("ticket_view_loaded",function(event,data){
jQuery('.redactor').insertAfter('#original_request');
});

function changeOrder(){
var ID = [];
jQuery('#' + id_value).find(".conversation").each(function(){
ID.push(jQuery(this).attr('data-timestamp'));
});
ID = ID.sort().reverse();
jQuery(ID).each(function(i,item){
jQuery('#' + id_value).append(jQuery('[data-timestamp=' + item + ']'));
});
}

function reorderNotes(){
if(jQuery('#all_notes').length)
{
id_value = "all_notes";
changeOrder();
}
else
{
id_value = "all_activities";
changeOrder();
}
}

jQuery('#Pagearea').ajaxComplete(function(){
reorderNotes();
});
//jQuery('#all_notes').after(jQuery('#show_more'))

jQuery(document).ready(function() {
jQuery('#all_notes').after(jQuery('#show_more'))
})
</script>
<style type="text/css">
.conversation_thread {
border: 0;
}
#show_more {
padding: 0 10px 40px;
}
.conversation_thread.redactor {
margin-bottom: -30px;
margin-top: 0px;
}
</style>


 


To Aravind S / anyone from Freshdesk:

1) I see in the Javscript console a warning:
TypeError: r is null
...e,t,i,n){this.options=n||{};var r=$(e);this.name=r.name,this.choices_visible=!1,...

The warning goes away if jQuery('.redactor').insertAfter('#original_request'); is removed.
What is the cause of that warning and how can it be avoided?

2) That ajaxComplete is indiscriminate and may fire multiple times. A better solution is:
  jQuery('#Pagearea').ajaxComplete(function(event, xhr, settings) {
var patt = /^\/helpdesk\/tickets\/\d+\/notes\?/g;
if (patt.test(settings.url)) {
reorderNotes();
}
});

 


Badge +3

I'm happy to announce that our app to reverse the sort order is released on the Marketplace.




The app is free of charge and I hope it solves your needs and that your agents will like it! We will be happy to get your feedback.




Look here for more info:


https://apps.freshdesk.com/reversed_sort_order/