# MODX Console Init

**URL:** <https://community.modx.com/t/modx-console-init/1445>\
**Category:** Development\
**Created:** [September 1, 2019, 8:50pm UTC](https://community.modx.com/t/modx-console-init/1445 "2019-09-01T20:50:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dontstopmenow](https://community.modx.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dontstopmenow](https://community.modx.com/u/dontstopmenow)\
**Post date:** [September 1, 2019, 8:50pm UTC](https://community.modx.com/t/modx-console-init/1445/1 "2019-09-01T20:50:36Z")

</div>

Hey there, folks.

Can someone show me a little more information about the script output to the MODX console widget?

[This docs](https://docs.modx.com/revolution/2.x/developing-in-modx/advanced-development/custom-manager-pages/modext/modx.console) is pretty nice, but i cannot understand how call my Console in custom Menu button.

I always get JS error:

```
Uncaught SyntaxError: Unexpected token return

```

I will be appreciate for any help!

---

<div class="post-metadata">

**Author:** ![markh](https://community.modx.com/user_avatar/community.modx.com/markh/32/36_2.png) [@markh](https://community.modx.com/u/markh)\
**Post date:** [September 1, 2019, 10:07pm UTC](https://community.modx.com/t/modx-console-init/1445/2 "2019-09-01T22:07:21Z")

</div>

Can you show the code that’s currently throwing that error?

---

<div class="post-metadata">

**Author:** ![dontstopmenow](https://community.modx.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dontstopmenow](https://community.modx.com/u/dontstopmenow)\
**Post date:** [September 2, 2019, 5:28am UTC](https://community.modx.com/t/modx-console-init/1445/3 "2019-09-02T05:28:03Z")

</div>

Hi Mark, thanks for attention to my problem!

This error i get, couse i did not clear my cache. But i am pretty sure that I’m doing something wrong, i’m weak in ExtJS. And I need help to move the right way.

Firstly, here is my **console.window.js** file, which i load in my controller.

```
var topic = '/generateinfo/';
var register = 'mgr';
var console = MODx.load({
    xtype: 'modx-console'
    , register: register
    , topic: topic
    , show_filename: 0
    , listeners: {
        'shutdown': {
            fn: function () {
                /* do code here when you close the console */
            }, scope: this
        }
    }
});
console.show(Ext.getBody());

MODx.Ajax.request({
    url: generateInfo.config.connector_url
    , params: {
        action: 'mgr/generateinfo'
        , register: register
        , topic: topic
    }
    , listeners: {
        'success': {
            fn: function () {
                console.fireEvent('complete');
            }, scope: this
        }
    }
});

```

And here is my processor, generateinfo

```
class generateInfoProcessor extends modObjectProcessor
{

    public function process()
    {

        $modx->log(modX::LOG_LEVEL_INFO,'An information message in normal colors.');
        $modx->log(modX::LOG_LEVEL_ERROR,'An error in red!');
        $modx->log(modX::LOG_LEVEL_WARN,'A warning in blue!');

    }
}
return 'generateInfoProcessor';

```

I want to understand, how i can call console with this logs…

---

<div class="post-metadata">

**Author:** ![markh](https://community.modx.com/user_avatar/community.modx.com/markh/32/36_2.png) [@markh](https://community.modx.com/u/markh)\
**Post date:** [September 2, 2019, 12:01pm UTC](https://community.modx.com/t/modx-console-init/1445/4 "2019-09-02T12:01:06Z")

</div>

Because the request to the connector contains a `topic` and `register` parameter, the request automatically enables the register logging (`modRequest.registerLogging()`, called in `modManagerRequest.loadErrorHandler()`) which means log messages are automatically written to where the console will read from.

I’m guessing the JS error you see comes from the lack of a response in the `process()` method. You should end it with `return $this->success('Optional Success Message');`

Your calls to `$modx->log` should also be `$this->modx->log` as you’re in a class.

---

<div class="post-metadata">

**Author:** ![dontstopmenow](https://community.modx.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dontstopmenow](https://community.modx.com/u/dontstopmenow)\
**Post date:** [September 2, 2019, 3:28pm UTC](https://community.modx.com/t/modx-console-init/1445/5 "2019-09-02T15:28:35Z")

</div>

Ok, got it! Thank you very much. But how should i correctly call the console using the “Menu” button? I think I should do something like this?

`'handler' => 'MODx.generateinfo(); return false;'`

Or not? If i do it, i get error:

```
Uncaught TypeError: MODx.generateinfo is not a function
    at HTMLAnchorElement.onclic
```

---

<div class="post-metadata">

**Author:** ![markh](https://community.modx.com/user_avatar/community.modx.com/markh/32/36_2.png) [@markh](https://community.modx.com/u/markh)\
**Post date:** [September 2, 2019, 3:55pm UTC](https://community.modx.com/t/modx-console-init/1445/6 "2019-09-02T15:55:55Z")

</div>

Try wrapping the code you posted before (which has the `MODx.load({})` ) in a function, and calling that function in the handler. Or is that already your `MODx.generateinfo` ?

---

<div class="post-metadata">

**Author:** ![dontstopmenow](https://community.modx.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dontstopmenow](https://community.modx.com/u/dontstopmenow)\
**Post date:** [September 2, 2019, 4:37pm UTC](https://community.modx.com/t/modx-console-init/1445/7 "2019-09-02T16:37:47Z")

</div>

Here is my js file:

```
Ext.extend(MODx, Ext.Component, {
    infoGenerator: function () {
        var topic = '/infoGenerator/';
        var register = 'mgr';
        var console = MODx.load({
            xtype: 'modx-console'
            , register: register
            , topic: topic
            , show_filename: 0
            , listeners: {
                'shutdown': {
                    fn: function () {
                        /* do code here when you close the console */
                    }, scope: this
                }
            }
        });
        console.show(Ext.getBody());

        MODx.Ajax.request({
            url: infoGenerator.config.connector_url
            , params: {
                action: 'mgr/infogenerator'
                , register: register
                , topic: topic
            }
            , listeners: {
                'success': {
                    fn: function () {
                        console.fireEvent('complete');
                    }, scope: this
                }
            }
        });
    }
});

```

Still get same error:

`MODx.infoGenerator is not a function`

---

<div class="post-metadata">

**Author:** ![dontstopmenow](https://community.modx.com/letter_avatar_proxy/v4/letter/d/8797f3/32.png) [@dontstopmenow](https://community.modx.com/u/dontstopmenow)\
**Post date:** [September 2, 2019, 4:45pm UTC](https://community.modx.com/t/modx-console-init/1445/8 "2019-09-02T16:45:25Z")

</div>

Nevermind, Mark, it was my fault with addJavascript. Now everything works fine! Thanks so much for your amazing help!

![exmp](https://modx-community.s3.dualstack.us-east-1.amazonaws.com/original/1X/23685d13df30539316e1bf1ff529339969705c4e.jpeg)
