AnsweredAssumed Answered

Ajax call using global JS after login not working in Sugar 7

Question asked by Maulik Shah on Mar 11, 2015
Latest reply on Mar 30, 2015 by Emil Maran
I want to add global JS  after login and that JS file has some ajax call.In Sugar Community after_ui_frame logic_hook works for me but in Sugar7 after_ui_frame not working.

I have included my custom js from "custom/include/MVC/View/tpls/sidecar.tpl" and code is

{literal}
    <script type='text/javascript'>
        $(document).ready(function () {
            function appendScript(url) {
                debugger;
                var head = document.getElementsByTagName('body')[0];
                var theScript = document.createElement('script');
                theScript.type = 'text/javascript';
                theScript.src = url;
                head.appendChild(theScript);
            }

            appendScript('custom/clients/base/views/Test/test.js');
        });
    </script>
{/literal}

This test.js is included .

test.js file contains below code
var arg = 'test/getdata';
app.api.call('create', app.api.buildURL(arg),
    {
        success: function (data) {
            alert(data);
        }

    }
);

I have make entry point at module level and that is located at
"custom/modules/Test/clients/base/api/Test.php" and included properly.

In this Ajax call I have error like "undefined variable:app". So it seems like when you include javascript at global level it is not finding the main app object and so i am unable to make default sugar api call. i guess this should be working at module level in record.js

Anybody can help me ?

Outcomes