How to call merge function in custom page ?

Hello

How to call merge function in custom page ?

Parents Reply Children
  • Hi Bhavin,

    Please check your syntax in your code. Seems like your syntax is not correct.

    The code i've shared with you is tested. So, there has to be a mistaken parentheses or forgotten comma.

    Try to share full code see, if we can get your syntax error.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik Tümer

    Here is my full code.

    custom/modules/Configurator/test.php

    <?php
    ini_set("display_errors",1);
    error_reporting(E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
    global $db, $sugar_config, $mod_strings, $app_strings;
    require_once('include/SugarQuery/SugarQuery.php');
    require_once('data/SugarBean.php');
    ?>
    <script src="custom/modules/Configurator/test.js"></script>
    <input type="button" onclick="do_magic();" value="click" name="do_magic" id="do_magic"/>
    
    
    

    custom/modules/Configurator/test.js

    initialize: function (options) {  
        console.log(this);
            this.plugins.push('MergeDuplicates');  
            console.log("initialize", this.plugins);  
            this._super('initialize', [options]);  
            this.context.on('button:do_magic:click', this.do_magic, this);  
        },     
        do_magic: function() {  
            console.log("Magic!");  
            var self = this;  
            var records = app.data.createBeanCollection('Accounts');  
            records.fetch({  
                'filter':[{  
                    "id": {  
                        '$in':[  
                            'de4333f7-ed82-4481-557e-5780b9505dd7',  
                            '6ab35041-759b-78f0-0a3c-577f90e687fd'  
                        ]  
                    }  
                }],  
                success:function (collection) {  
                    console.log(collection);  
                    self.mergeDuplicates(collection);  
                }  
            })  
        },  
    
  • Hi Bhavin,

    Okay, I understand your problem. Because you are using BWC you cannot initiate your plugin.

    In order to add your plugin into your BWC modules. You need to customise bwc view of sidecar.

    Create a file ./custom/clients/base/views/bwc/bwc.js with following code block;

    /*
     * Your installation or use of this SugarCRM file is subject to the applicable
     * terms available at
     * support.sugarcrm.com/.../.
     * If you do not agree to all of the applicable terms or do not have the
     * authority to bind the entity as an authorized representative, then do not
     * install or use this SugarCRM file.
     *
     * Copyright (C) SugarCRM Inc. All rights reserved.
     */
    ({
      'extendsFrom': 'BwcView',
      initialize: function (options) {
            if ( this.plugins.indexOf('MergeDuplicates') == -1 ) 
                 this.plugins.push('MergeDuplicates');
            console.log("initialize", this.plugins);
            this._super('initialize', [options]);
        },
    })
    

    Then you need to change your test.js like this;

    var do_magic = function() {  
        console.log("Magic!");  
        var self = this; 
        // You need to set this module name with records for merging
        var mergeModule = "Accounts";
    
    
        //getting app from parent window
        var app = window.parent.SUGAR.App;
        console.log("app", app);
        
        //accessing bwc view
        var bwcView = app.controller.layout._components[0];
        //getting existing bwc module name a side
        var previousContextModule = bwcView.context.get("module");
        //hacking bwc module context for mergeDuplicates drawer
        bwcView.context.set("module", mergeModule);
        console.log("bwcView", bwcView);
        
        var bwcView_plugins = app.controller.layout._components[0].plugins;
        console.log("bwcView_plugins", bwcView_plugins);
        //init collection for given merge module
        var records = app.data.createBeanCollection(mergeModule);  
        records.fetch({  
            'filter':[{  
                "id": {  
                    '$in':[  
                        'a0d1575b-b89a-852e-8e67-5795e4dee355',  
                        '955d508f-4a8e-6bdf-b449-5795e4d41fb1'  
                    ]  
                }  
            }],  
            success: function (collection) {  
                console.log(collection);
                //open merge duplicates drawer
                bwcView.mergeDuplicates(collection);  
            },
            //this will run every after ajax call without its state(success or fail)
            complete: function () {
                //setting back the context module
                bwcView.context.set("module", previousContextModule);
                console.log("bwcView reset context", bwcView);
            } 
        })  
    };
    

    I've tested it works full functional.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik Tümer,

    Thanks for share this code

    when i call do_magic function on button click event its shows do_magic is not a function.

    here is my code.

    custom/modules/Configurator/test.php

    <?php

    ini_set("display_errors",1);

    error_reporting(E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE);

    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

    global $db, $sugar_config, $mod_strings, $app_strings;

    require_once('include/SugarQuery/SugarQuery.php');

    require_once('data/SugarBean.php');

    ?>

    <script src="custom/modules/Configurator/test.js">

    </script>

    <input type="button" onclick="do_magic();" value="click" name="do_magic" id="do_magic"/>

    =================================

    custom/modules/Configurator/test.js

    var do_magic = function() {    
        console.log("Magic!");    
        var self = this;   
        // You need to set this same module name with records for merging  
        var mergeModule = "Accounts";  
      
      
        //getting app from parent window  
        var app = window.parent.SUGAR.App;  
        console.log("app", app);  
          
        //accessing bwc view  
        var bwcView = app.controller.layout._components[0];  
        //getting existing bwc module name a side  
        var previusContextModule = bwcView.context.get("module");  
        //hacking bwc module context for mergeDuplicates drawer  
        bwcView.context.set("module", mergeModule);  
        console.log("bwcView", bwcView);  
          
        var bwcView_plugins = app.controller.layout._components[0].plugins;  
        console.log("bwcView_plugins", bwcView_plugins);  
        //init collection for given merge module  
        var records = app.data.createBeanCollection(mergeModule);    
        records.fetch({    
            'filter':[{    
                "id": {    
                    '$in':[    
                        'de4333f7-ed82-4481-557e-5780b9505dd7',    
                        '6ab35041-759b-78f0-0a3c-577f90e687fd'    
                    ]    
                }    
            }],    
            success: function (collection) {    
                console.log(collection);  
                //open merge duplicates drawer  
                bwcView.mergeDuplicates(collection);    
            },  
            //this will run every after ajax call without its state(success or fail)  
            complete: function () {  
                //setting back the context module  
                bwcView.context.set("module", previusContextModule);  
                console.log("bwcView reset context", bwcView);  
            }   
        })    
    };  
    

    I want to open merge drawer on button click.

    Where i m wrong can you help me.

    Thanks & Regards

    Bhavin Patel

  • Hi Bhavin,

    I used your test.php;

    <?php  
    if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');  
    global $db, $sugar_config, $mod_strings, $app_strings;  
    require_once('include/SugarQuery/SugarQuery.php');  
    require_once('data/SugarBean.php');  
    ?>  
    <script src="custom/modules/Configurator/test.js"></script>
    <input type="button" onclick="do_magic();" value="click" name="do_magic" id="do_magic"/>
    

    And navigated to /#bwc/index.php?module=Configurator&action=test

    Did you run repairs? Quick Repair and Rebuild?

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik Tümer

    Thank you so much.

    its working .

    you owe me one...........

    you have saved me at the last stretch............

    getting here was so complicated, thanks for getting me out.........

    THANK YOU SO MUCH

  • Hi Bhavin,

    I'm glad it works

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik,

    It is working well. However I want to set the primary record id in the merge process. How can we set that ?