Jira Plugin Webpanel loaded multiple times in List View

Hi!

Jira 8.5.2, ATLAS Version 8.0.16

I am writing a Jira Server Plugin which incorporates a Webpanel which uses a velocity file.

When I open an Issue in the Detail View, everything works fine:

AJS.toInit(function() {
    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
         var $context = $(context);
         switch(reason) {
             case JIRA.CONTENT_ADDED_REASON.panelRefreshed:
                $context.find(element_in_velocity).each(function() {
                   doSomething();
                });
               break;
    });
}

At the end of my velocity file I am using


<script>
    console.log('I am here !!!');
</script>


In the console I see, that ‘I am here !!!’ appears only once.

When I view Issues in the ListView, things get complicated…

Because

 

    JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) 

doesnt work, when opening Issues in the List View, I am using


            JIRA.bind(JIRA.Events.ISSUE_REFRESHED, function(e, context, reason) {
              doSomething();
            });

Unfortunately, ‘I am here !!!’ sometimes appears 3 times and overwrites data that I had already changed during the loading.

I dont now how to handle this and why this happens.

Any hints on how to solve this would be greatly appreciated!

Thanx in advance!’
Hans