How to call merge function in custom page ?

Hello

How to call merge function in custom page ?

Parents Reply Children
  • Hi Bhavin,

    Sorry for misunderstanding

    Give a try this code; I didn't test it. Let me know if it doesn't work i can try here really quick.

    var primary = model;
    // or
    // var primary = model.get("id");
    
    
    var models; // <= set here duplicated models
    app.drawer.open({
        layout: 'merge-duplicates',
        context: {
            primary: primary || null,
            selectedDuplicates: models
        }
    });
    

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik Tümer

    var app = window.parent.SUGAR.App; 
        var primary = '97578173-86b3-b038-3d6b-577f912be9fc';
        var models = '34d6269a-39c9-7e44-9680-5755710e8c0f';
        app.drawer.open({    
            layout:'merge-duplicates',    
            context: {    
                      primary: primary || null,  
                     selectedDuplicates: models 
            }    
        }); 
    

    i m using this code for bwc page but facing error & screen shot is attached.

  • Hi Bhavin,

    Can you give models as model rather than record id?

    This code block what Sugar uses in SugarCRM 7.7.

    Let me know if it doesn't work as well.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hello Tevfik Tümer

    Thanks for prompt reply.

    I tried models as model but still same error.

    I m using Sugarcrm 7.6

  • Hi Bhavin,

    Sorry for late response, I was really busy.

    I tired in my development instance. I was able to open merge drawer with following lines;

        initialize: function (options) {
            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':[
                            '1d04422d-2225-7171-13f8-5795e4bf6e42',
                            'ad73be90-34c8-f292-cd5b-5795e4eb1074'
                        ]
                    }
                }],
                success:function (collection) {
                    console.log(collection);
                    self.mergeDuplicates(collection);
                }
            })
        }
    

    Simple explanation about behind the scenes.

    In order to open mergeDuplicates drawer you need to include plugin. Depend on where you are going to do this functionality you need to check it exist or not. If it's not exist in your plugings you can add it like I added in initialize function.

            this.plugins.push('MergeDuplicates');
            console.log("initialize", this.plugins);
    

    After that you would need to create your beancollection. Then give it to mergeDuplicates function.

    Thats all. I've tested on 7.6.2.1 ENT.

    Hope it helps

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

  • Hi Tevfik Tümer

    My initialize function does not executes

    it says,

    Uncaught SyntaxError: Unexpected token (

    I have included the js in bwc page.

    Thanks & Regards.

    Bhavin Patel

  • 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