Results 1 to 10 of 10

Thread: QuickCreate form in subpanel does not create relationship

  1. #1
    johnfd is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    15

    Default QuickCreate form in subpanel does not create relationship

    Hi all,

    I' m facing the following issue. I have added a Contacts subpanel in my custom module's detail view with 'Create' and 'Select' buttons to display related contacts. The 'Create' button is configured to display the Contacts QuickCreate form. When I click 'Save' to create a new contact with this form, the contact record is created correctly BUT the relationship between the contact record and my module's record is not saved in the relationship table.

    please help
    SugarCRM OS Version 4.5.1e
    Windows XP Pro SP2
    IIS 5.1
    PHP 5.2.3
    MySQL 5.0.45

  2. #2
    pblag's Avatar
    pblag is offline Sugar Community Member
    Join Date
    Jul 2006
    Location
    Ukraine (Chernivtsy)
    Posts
    347

    Smile Re: QuickCreate form in subpanel does not create relationship

    Hi!

    As i know you have to write your own code for creating relations.

    You have to check function handleSave from file modules/Conacts/ContactsFormBase.php

    Hope it will help you!
    Petro Blagodir
    petro@blagodir.ua
    http://www.blagodir.com
    Blagodir Ltd.( SugarCRM - Consultations, Development and Support)

  3. #3
    johnfd is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    15

    Default Re: QuickCreate form in subpanel does not create relationship

    Hi pblag, thank you for your post!

    I checked the function handleSave in Contacts/ContactFormBase.php file. It lead to me to the fields defined in Contacts/Contact.php and the relationships defined in Contacts/vardefs.php. Should I change the code in Contacts/Contact.php (add new fields) in order to have a quick save functionality for my module? Any help would greatly appreciated.
    SugarCRM OS Version 4.5.1e
    Windows XP Pro SP2
    IIS 5.1
    PHP 5.2.3
    MySQL 5.0.45

  4. #4
    pblag's Avatar
    pblag is offline Sugar Community Member
    Join Date
    Jul 2006
    Location
    Ukraine (Chernivtsy)
    Posts
    347

    Wink Re: QuickCreate form in subpanel does not create relationship

    Hi!

    Yes, i think you have to check the function save_relationship_changes in the Contacts/Contact.php

    Unfortunately we have few different ways how to save relationships and i guess that it depends of sugar version.

    Anyway you can add your own code and it should work.

    Just remember that you have to create relationships manually.
    Petro Blagodir
    petro@blagodir.ua
    http://www.blagodir.com
    Blagodir Ltd.( SugarCRM - Consultations, Development and Support)

  5. #5
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: QuickCreate form in subpanel does not create relationship

    Hello johnfd,

    If you download the Sugar Forums module (here: http://www.sugarforge.org/frs/downlo...e-OS-4.5.1.zip), you'll find a custom module is created with quite a few subpanels. Check the vardefs.php files to see how to set up the relationships correctly.
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  6. #6
    wiela is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    11

    Default Re: QuickCreate form in subpanel does not create relationship

    Hello All,

    Quote Originally Posted by pblag

    Yes, i think you have to check the function save_relationship_changes in the Contacts/Contact.php

    Unfortunately we have few different ways how to save relationships and i guess that it depends of sugar version.

    Anyway you can add your own code and it should work.

    Just remember that you have to create relationships manually.
    But it definitely will break any/all customizations when upgrading? It is bad way, imho.
    I still wonder if there is no clear and safe way to relate two modules and keep this relation safe when upgrading?
    Custom logic hooks?
    But it is some kind of workaround (i wouldn't call it solution)...(saving relationships in custom logic, deleting relations automatically). We definitely need to have one and clear way for managing relationships, preferably in the sugarbean.php
    save_relationship_changes() function.

  7. #7
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: QuickCreate form in subpanel does not create relationship

    Hello wiela,

    Please take a look at the example module I posted. When adding a custom module through the Module Loader, you can create relationships that will be upgrade-safe. The Forums module is a perfect example of this.
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  8. #8
    wiela is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    11

    Default Re: QuickCreate form in subpanel does not create relationship

    Hello Julian
    Quote Originally Posted by julian

    Please take a look at the example module I posted. When adding a custom module through the Module Loader, you can create relationships that will be upgrade-safe. The Forums module is a perfect example of this.
    I could be wrong, but it is safe only in one direction., and based on rather tricky assumption that all relations to other modules already made in the Forums module will be kept in the future upgrades.
    What should we do, if we would like to relate, say, Documents to some Custom module (not opposite) ?
    In this case we need to modify Documents module code (if not using custom logic hooks), and this modification/customization will work till first/ordinary upgrade, which replaces Documents module's files.

    One workaround, IMHO, is to use custom logic hooks.
    Let's say we need to relate Documents to Custom module 'CustomMod', so we need to save logic_hooks.php file in /custom/modules/Documents/

    and write in that file:
    hook_version = 1;

    $hook_array['before_save'][] = Array (
    1, 'SaveRelations', 'custom/modules/Documents/save_relations.php', 'SaveRelations', 'SaveRelations'
    );


    In the file 'save_relations.php' we define the class 'SaveRelations and the Method 'SaveRelations':

    class SaveRelations {
    function SaveRelations(&$bean, $event, $arguments) {


    $GLOBALS['log']->debug("Documents custom logic hook, SaveRelations()");
    $ff = print_r($_REQUEST);
    $GLOBALS['log']->debug($ff);

    if (!empty($_REQUEST['parent_type']) && $_REQUEST['parent_type'] == 'CustomMod') {
    $bean->load_relationship('CustomModRel');
    $bean->CustomModRel->add($_REQUEST['return_id']);

    }
    }
    }



    Here 'CustomModRel' is a link to the relationship 'custommod_documents', and this link should be defined in the
    Documents Extension (we don't want it to be touched when upgrading) vardefs file (that is custom/Extension/modules/Documents/Ext/vardefs/сustommod.php):
    $dictionary['Document']['fields']['CustomModRel'] = array (
    'name' => 'CustomMod',
    'type' => 'link',
    'relationship' => 'CustomMod_documents',
    'module'=>'CustomMod',
    'bean_name'=>'CustomMod',
    'source' => 'non-db',
    'vname' => 'LBL_CUSTOMMOD',
    );



    Many-to-Many relationship for this module should be defined in the 'metadata/custommod_documentsMetadata.php':
    $dictionary['custommod_documents'] = array (
    'table' => 'custommod_documents',
    'fields' => array (
    array ('name' =>'id', 'type' =>'char', 'len'=>'36', 'default'=>''),
    array ('name' =>'document_id', 'type' =>'char', 'len'=>'36', ),
    array ('name' =>'custommod_id', 'type' =>'char', 'len'=>'36',),
    array ('name' => 'date_modified','type' => 'datetime'),
    array ('name' =>'deleted', 'type' =>'bool', 'len'=>'1', 'default'=>'0', 'required'=>true),
    ),

    'indices' => array (
    array ('name' =>'custommod_documentspk', 'type' =>'primary', 'fields'=>array('id')),
    array ('name' =>'idx_con_opp_con', 'type' =>'index', 'fields'=>array('custommod_id')),
    array ('name' =>'idx_con_opp_opp', 'type' =>'index', 'fields'=>array('custommod_id')),
    array ('name' => 'idx_custommod_documents', 'type'=>'alternate_key', 'fields'=>array('custommod_id','document_id'))
    ),

    'relationships' => array ('
    custommod_documents' => array (
    'lhs_module'=> 'CustomMod',
    'lhs_table'=> 'custommod',
    'lhs_key' => 'id',
    'rhs_module'=> 'Documents',
    'rhs_table'=> 'documents', '
    rhs_key' => 'id',
    'relationship_type'=>'many-to-many',
    'join_table'=> 'custommod_documents', '
    join_key_lhs'=>'custommod_id',
    'join_key_rhs'=>'document_id',
    )
    )
    )



    I still suppose, that simply relating (many-to-many) two modules could be done automatically (without any hardcoding in the modules) in the sugarbean.php (deleting relationship already works automatically), because all we need to know for this task is already defined in the relationship (vardefs.php)

  9. #9
    julian's Avatar
    julian is offline Sugar Team Member
    Join Date
    Sep 2004
    Posts
    1,639

    Default Re: QuickCreate form in subpanel does not create relationship

    A structure does exist for 'extended' vardefs, which are created by the Module Loader and which are upgrade-safe. I'd search the forums for "vardefs.ext.php" -- unfortunately, I don't have much experience with them myself.

    If the vardefs.ext.php option does not work for you, then the code you posted above is probably the best way to go about this (although I always hesitate to re-implement logic that's already in Sugar).

    Thanks!
    Julian Ostrow
    Systems and Applications Engineer
    SugarCRM Inc.

  10. #10
    johnfd is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    15

    Default Re: QuickCreate form in subpanel does not create relationship

    Hello Julian,

    Thanks for posting.
    I 've tried the Forums module but it does not exhibit related Contacts. Then I found the Widgets module which shows a Contacts subpanel in its DetailView. But, unfortunately, neither this module can relate a newly created contact to a widget record (it uses the 'normal' Create button rather the QuickCreate one).
    So it seems that there's no - known to the public- way to handle such relationships other than altering the code of a 'system' module (in our case the 'Contacts' module). Which is pretty bad for updates, modifications etc.
    Unless, the there is a way to use logic hooks as wiela posted (I haven't tried it). Wiela, thanks for the idea.

    John
    SugarCRM OS Version 4.5.1e
    Windows XP Pro SP2
    IIS 5.1
    PHP 5.2.3
    MySQL 5.0.45

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. problemi step 6 di SugarSuite-Full-4.0.1h
    By lucia in forum Italiano
    Replies: 0
    Last Post: 2006-12-27, 08:50 AM
  2. Asterisk Patch 1.1.0 Crash on logon
    By skyracer in forum Help
    Replies: 6
    Last Post: 2006-07-08, 06:30 AM
  3. Replies: 7
    Last Post: 2006-06-06, 07:56 PM
  4. 4.0.1 Installation Problem
    By clawton in forum Help
    Replies: 14
    Last Post: 2006-02-13, 04:17 PM
  5. Query erro after 4.0 upgrade
    By ldebernardini in forum Help
    Replies: 20
    Last Post: 2006-01-13, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •