JS file does not work when I create custom button like button Edit in the record menu contacts module

My steps:
1. Create array in the record.php like this
        5 =>  array ('type'  => 'rowaction',
                            'event' => 'button:create_data_po:click',
                            'name'  => 'create_data_po',
                            'label' => 'LBL_CREATE_DATA_PO_C',
                             'acl_action' => 'view'),
2. Create lng-file (en_us.addContactsActionLink.php):
    <?php     $mod_strings['LBL_CREATE_DATA_PO_C'] = 'Crate Data PO';
3. Create record.js file:
    ({
    extendsFrom: 'RecordView',

    zipJSON: {},

    initialize: function (options) {
        app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});
        this.context.on('button:create_data_po:click', this.create_data_po, this);
    },

    create_data_po: function() {        
        var ContID = this.model.get('id');        
    $('a[name=create_data_po]').attr('target', '_blank');
    $('a[name=create_data_po]').attr('href', 'http://**************************?id='+ContID);
    window.open($('a[name=create_data_po]').attr('href'));
    }
})
4. Create manifest.php (for uploading all this files):
  <?php
    $manifest = array(
        'acceptable_sugar_flavors'  => array('CE','PRO','CORP','ENT','ULT'),
        'acceptable_sugar_versions' => array('exact_matches' => array(),
                         'regex_matches' => array('(.*?)\\.(.*?)\\.(.*?)$')),
        'author'                 => 'Nick Gamora',
        'description'         => 'Adding Contacts menu action Links',
        'icon'                     => '',
        'is_uninstallable'  => true,
        'name'                  => 'addContactsActionLink',
        'published_date'   => '2016-08-17 2016 15:28:04',
        'type'                    => 'module',
        'version'               => '1',
    );
   
    $installdefs = array(
        'id' => 'Adding',
        'copy' => array(
            0 => array(
                'from' => '<basepath>/record.php',
                'to'   => 'custom/modules/Contacts/clients/base/views/record/record.php',
            ),
        1 => array(
                'from' => '<basepath>/en_us.addContactsActionLink.php',
                'to'   => 'custom/Extension/modules/Contacts/Ext/Language/en_us.addContactsActionLink.php',
            ),
        2 => array(
                'from' => '<basepath>/record.js',
                'to'   => 'custom/modules/Contacts/clients/base/views/record/record.js ',
            ),
        ),       
    );
?>

But after upload and repair & rebuild I can not see that js file works. I see link was added, but both consle.log and alert do not work.

Does anybody know how to do it correct?
I need my url open in the new tab after I  click the button ('Crate Data PO').

Parents
  • Hi Nick Gamora

    Try it like this:

    In record.js file under your function:

    create_data_po: function() {        
        var ContID = this.model.get('id');      

        var link = 'http://******************?id='+ContID;

        window.open(link, '_blank');
        }
    })

    or 

    In record.js file add this code in initialize function:

    this.on("render", this.SetCreateLink, this);

    Outside initialize function add this:

    SetCreateLink: function(){

       var ContID = this.model.get('id');
       $('a[name=create_data_po]').attr('target', '_blank');
       $('a[name=create_data_po]').attr('href', 'http://**************************?id='+ContID);

    },

    Hope this Help..!!

    Best Regards

    S Ramana Raju

  • My problem that I set console.log and alert and both of them does not work.I see that js file is present but not live,not work. How anybody know what it is?
    ({
        extendsFrom: 'RecordView',
        console.log("start");
        zipJSON: {},

        initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});

            console.log("initialize");

            this.context.on('button:create_data_po:click', this.create_data_po, this);

        },
        create_data_po: function(elem) {

        elem.preventDefault();
        console.log("create_data_po");
           
            var ContID = this.model.get('id');
            console.log("id_contact="+ContID);

        $('a[name=create_data_po]').attr('target', '_blank');
        $('a[name=create_data_po]').attr('href', 'https://www.**********.php?id='+ContID);
        window.open($('a[name=create_data_po]').attr('href'));
            

        //var url = 'http://www.***********.php?id='+ContID;
        //console.log("url="+url);
        //window.open(url, '_blank');        
        }
    })

Reply
  • My problem that I set console.log and alert and both of them does not work.I see that js file is present but not live,not work. How anybody know what it is?
    ({
        extendsFrom: 'RecordView',
        console.log("start");
        zipJSON: {},

        initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args:[options]});

            console.log("initialize");

            this.context.on('button:create_data_po:click', this.create_data_po, this);

        },
        create_data_po: function(elem) {

        elem.preventDefault();
        console.log("create_data_po");
           
            var ContID = this.model.get('id');
            console.log("id_contact="+ContID);

        $('a[name=create_data_po]').attr('target', '_blank');
        $('a[name=create_data_po]').attr('href', 'https://www.**********.php?id='+ContID);
        window.open($('a[name=create_data_po]').attr('href'));
            

        //var url = 'http://www.***********.php?id='+ContID;
        //console.log("url="+url);
        //window.open(url, '_blank');        
        }
    })

Children
No Data