Button in title bar

Hello, I am trying to create buttons in the title bar that will send a msg on click.
I am using an ui_template and creating the button is no problem.
I am failing on sending the msg on click, here is my code in the ui_template:

<script>
    var nodes = document.createElement('BUTTON');
    nodes.addEventListener('click', this.scope.send({payload: "test"}));
    nodes.innerHTML = 'NODES';
    var titleBar = document.getElementById("nr-dashboard-toolbar");
    titleBar.appendChild(nodes);
</script>

I tried different approaches but none worked. Does someone have experience with this?
I am thankful for any hint.

Well I got it working with some adjustments just some minutes after creating the thread... tried for hours before.

<script>
    var theScope = scope;
    
    var nodes = document.createElement('BUTTON');
    nodes.addEventListener('click', sendPayload);
    nodes.innerHTML = 'NODES';
    var titleBar = document.getElementById("nr-dashboard-toolbar");
    titleBar.appendChild(nodes);
    
    function sendPayload(){
        theScope.send("1");
    }
</script>
4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.