How to convert from opportunity module to a custom module?

I have a custom module called PROJECT, i want to convert an opportunity to a project, both modules have some fields in common. How do i get the data from opp to project for those in common fields?

Using Sugar 7.7.

I have already tried using the same method that converts a lead to an opportunity. It didn't work. Any help at all would be great.

  • Can you post the code you've already tried so we can see what might be wrong?

  • Basically I used the code base for the leads conversion process (converting lead to opportunity) and amended to suit the transfer to the new module.

    No errors in the sugar log so don't think it's a coding error. There's too much sections of code to put up here. Was just seeing if someone had done anything like this and if anyone had any ideas. Maybe the code base I'm using from the lead to opp convert is not the way to go about it.

  • The first step is to copy modules/Opportunities/clients/base/views/record/record.php to custom/modules/Opportunities/clients/base/views/record/record.php and add the following snippet:

        array (
            'type' => 'rowaction',
            'event' => 'button:convert_to_project:click',
            'name' => 'convert_to_project',
            'label' => 'Convert to Project',
            'acl_action' => 'view',
        ),

    So for example, my record.php would like like:

    <?php

    /*
    * Your installation or use of this SugarCRM file is subject to the applicable
    * terms available at
    * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/.
    * 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.
    */


    $viewdefs['Opportunities']['base']['view']['record'] = array(
        'buttons' => array(
            array(
                'type' => 'button',
                'name' => 'cancel_button',
                'label' => 'LBL_CANCEL_BUTTON_LABEL',
                'css_class' => 'btn-invisible btn-link',
                'showOn' => 'edit',
                'events' => array(
                    'click' => 'button:cancel_button:click',
                ),
            ),
            array(
                'type' => 'rowaction',
                'event' => 'button:save_button:click',
                'name' => 'save_button',
                'label' => 'LBL_SAVE_BUTTON_LABEL',
                'css_class' => 'btn btn-primary',
                'showOn' => 'edit',
                'acl_action' => 'edit',
            ),
            array(
                'type' => 'actiondropdown',
                'name' => 'main_dropdown',
                'primary' => true,
                'showOn' => 'view',
                'buttons' => array(
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:edit_button:click',
                        'name' => 'edit_button',
                        'label' => 'LBL_EDIT_BUTTON_LABEL',
                        'acl_action' => 'edit',
                    ),
                    array(
                        'type' => 'shareaction',
                        'name' => 'share',
                        'label' => 'LBL_RECORD_SHARE_BUTTON',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'pdfaction',
                        'name' => 'download-pdf',
                        'label' => 'LBL_PDF_VIEW',
                        'action' => 'download',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:convert_to_project:click',
                        'name' => 'convert_to_project',
                        'label' => 'Convert to Project',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'pdfaction',
                        'name' => 'email-pdf',
                        'label' => 'LBL_PDF_EMAIL',
                        'action' => 'email',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'divider',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:find_duplicates_button:click',
                        'name' => 'find_duplicates_button',
                        'label' => 'LBL_DUP_MERGE',
                        'acl_action' => 'edit',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:duplicate_button:click',
                        'name' => 'duplicate_button',
                        'label' => 'LBL_DUPLICATE_BUTTON_LABEL',
                        'acl_module' => 'Opportunities',
                        'acl_action' => 'create',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:historical_summary_button:click',
                        'name' => 'historical_summary_button',
                        'label' => 'LBL_HISTORICAL_SUMMARY',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:audit_button:click',
                        'name' => 'audit_button',
                        'label' => 'LNK_VIEW_CHANGE_LOG',
                        'acl_action' => 'view',
                    ),
                    array(
                        'type' => 'divider',
                    ),
                    array(
                        'type' => 'rowaction',
                        'event' => 'button:delete_button:click',
                        'name' => 'delete_button',
                        'label' => 'LBL_DELETE_BUTTON_LABEL',
                        'acl_action' => 'delete',
                    ),
                ),
            ),
            array(
                'name' => 'sidebar_toggle',
                'type' => 'sidebartoggle',
            ),
        ),
        'panels' => array(
            array(
                'name' => 'panel_header',
                'header' => true,
                'fields' => array(
                    array(
                        'name' => 'picture',
                        'type' => 'avatar',
                        'size' => 'large',
                        'dismiss_label' => true,
                        'readonly' => true,
                    ),
                    array(
                        'name' => 'name',
                    ),
                    array(
                        'name' => 'favorite',
                        'label' => 'LBL_FAVORITE',
                        'type' => 'favorite',
                        'dismiss_label' => true,
                    ),
                    array(
                        'name' => 'follow',
                        'label' => 'LBL_FOLLOW',
                        'type' => 'follow',
                        'readonly' => true,
                        'dismiss_label' => true,
                    ),
                ),
            ),
            array(
                'name' => 'panel_body',
                'label' => 'LBL_RECORD_BODY',
                'columns' => 2,
                'labels' => true,
                'labelsOnTop' => true,
                'placeholders' => true,
                'fields' => array(
                    array(
                        'name' => 'account_name',
                        'related_fields' => array(
                            'account_id'
                        )
                    ),
                    array(
                        'name' => 'date_closed',
                        'related_fields' => array(
                            'date_closed_timestamp'
                        )
                    ),
                    array(
                        'name' => 'sales_stage',
                    ),
                    'probability',
                    array(
                        'name' => 'commit_stage',
                        'span' => 6
                    ),
                    array(
                        'name' => 'amount',
                        'type' => 'currency',
                        'label' => 'LBL_LIKELY',
                        'related_fields' => array(
                            'amount',
                            'currency_id',
                            'base_rate',
                        ),
                        'span' => 6,
                        'currency_field' => 'currency_id',
                        'base_rate_field' => 'base_rate',
                    ),
                    array(
                        'name' => 'best_case',
                        'type' => 'currency',
                        'label' => 'LBL_BEST',
                        'related_fields' => array(
                            'best_case',
                            'currency_id',
                            'base_rate',
                        ),
                        'currency_field' => 'currency_id',
                        'base_rate_field' => 'base_rate',
                    ),
                    array(
                        'name' => 'worst_case',
                        'type' => 'currency',
                        'label' => 'LBL_WORST',
                        'related_fields' => array(
                            'worst_case',
                            'currency_id',
                            'base_rate',
                        ),
                        'currency_field' => 'currency_id',
                        'base_rate_field' => 'base_rate',
                    ),
                    array(
                        'name' => 'tag',
                        'span' => 12,
                    ),
                ),
            ),
            array(
                'name' => 'panel_hidden',
                'label' => 'LBL_RECORD_SHOWMORE',
                'hide' => true,
                'labelsOnTop' => true,
                'placeholders' => true,
                'columns' => 2,
                'fields' => array(
                    'next_step',
                    'opportunity_type',
                    'lead_source',
                    'campaign_name',
                    array(
                        'name' => 'description',
                        'span' => 12,
                    ),
                    'assigned_user_name',
                    'team_name',
                    array(
                        'name' => 'date_entered_by',
                        'readonly' => true,
                        'type' => 'fieldset',
                        'label' => 'LBL_DATE_ENTERED',
                        'fields' => array(
                            array(
                                'name' => 'date_entered',
                            ),
                            array(
                                'type' => 'label',
                                'default_value' => 'LBL_BY'
                            ),
                            array(
                                'name' => 'created_by_name',
                            ),
                        ),
                    ),
                    array(
                        'name' => 'date_modified_by',
                        'readonly' => true,
                        'type' => 'fieldset',
                        'label' => 'LBL_DATE_MODIFIED',
                        'fields' => array(
                            array(
                                'name' => 'date_modified',
                            ),
                            array(
                                'type' => 'label',
                                'default_value' => 'LBL_BY',
                            ),
                            array(
                                'name' => 'modified_by_name',
                            ),
                        ),
                    ),
                ),
            ),
        ),
    );

    This will add a button on the dropdown called 'convert to project'. The next, you'll want to create the controller for this. In custom/modules/Opportunities/clients/base/views/record/record.js, create the following file:

    ({
        extendsFrom: 'RecordView',
        initialize: function (options) {
            app.view.invokeParent(this, {type: 'view', name: 'record', method: 'initialize', args: [options]});
            this.context.on('button:convert_to_project:click', this.convert_to_project, this);
        },
        convert_to_project: function () {
            var Params = {
                "name": "name of the project",
                "description": "description of the project"
            };

            App.api.call('create', App.api.buildURL('Projects'), Params, {
                success: function (data) {
                    app.alert.show('message-id', {
                        level: 'success',
                        messages: 'New Project created!',
                        autoClose: true
                    });
                },
                error: function (errormessage)
                {
                    app.alert.show('message-id', {level: 'error',
                        messages: errormessage,
                        autoClose: true
                    });
                }
            });
        },
    });

    This will create a new record (assuming your Projects module is called Projects - you can check that by checking the URL of the project module).

    There's lots of tweaks you can make - e.g. giving the project extra details or changing the message on creation to something with the new project link in it. Let me know if you need more help

  • Hai Alan,

    It is creting a empty record. what changes has to done in js file so the module all records auto populate to custom module.Alan Apter