How to call merge function in custom page ?

Hello

How to call merge function in custom page ?

Parents Reply
  • Hi Bhavin,

    As far as i understand you are trying to merge the models in JavaScript which is on Client side.

    I'm little bit confused in merge operations. How are you going to decide which one will be the value to show in drawer?

    If you say use the second one, then you are not merging replacing it.

    If you are just merging the empty fields, than i would get attributes of first model then go through second model to compare. and using model.set update the one i wanted then use it in the Drawer. Make sense?

    Hope it helps.

    Best Regards

    Tevfik Tümer

    Developer Support Engineer

Children
  • Hi Tevfik Tümer,

    I am wring one code, which is finding the Contacts with Duplicate Name.

    I am displaying those duplicate records in table, selecting few duplicate rows.

    I have database record ids of each duplicate contact.

    How can I open drawer that do merge functionality same as List view?

  • 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);  
                }  
            })  
        },