---
# System prepended metadata

title: Hide unneccary messages

---

# Hide unneccary messages 


```
(function ($) {
  $(document).ready(function () {
    $('.MessageList').hide();
  });
  var select = document.getElementById('ideamessagestatus');
  function ideaStatus() {
    var selectedvalue = select.options[select.selectedIndex].value;

    let allList = document.querySelectorAll('.message-subject a');
    let messageIds = [];
    allList.forEach((message) => {
      if (message.href) {
        const entireLink = message.href;
        const spittedLink = entireLink.split('/').reverse();
        const id = spittedLink[0];
        messageIds.push(id);
      }
    });
    console.log('messages ids are ', messageIds);

    $.ajax({
      type: 'GET',
      url:
        '/plugins/custom/salescontainer/italent2/kudosleaderboard?statusvalue=' +
        selectedvalue,
      contentType: 'application/json',
      datatype: 'json',
      success: function (response) {
        let matchedMessages = [];
        matchedMessages = response.messages.filter((msg) => {
          if (messageIds.indexOf(msg.id) > -1) {
            $('.MessageList').show();
            return msg;
          } else {
            $('.MessageList').hide();
          }
        });
        console.log('matched Message ids are ', matchedMessages);

        let allDisplayedMessages = document.querySelectorAll(
          '.message-subject a',
        );
        // loop into message a tags
        allDisplayedMessages.forEach((m) => {
          const entireLink = m.href;
          const spittedLink = entireLink.split('/').reverse();
          const id = spittedLink[0];
          const shouldShow = !!matchedMessages.find((i) => i.id === id);

          if (!shouldShow) {
            const parent = $(m).parent().closest('tr');
            if (parent && parent.length > 0) {
              parent[0].style.display = 'none';
            }
          }
        });
      },
      error: function (data) {
        console.log(data);
      },
    });
  }
  select.onchange = ideaStatus;
  ideaStatus();
})(LITHIUM.jQuery);


```