Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By davec2

Thread: SOAP set_relationship with custom modules

  1. #1
    davec2 is offline Junior Member
    Join Date
    Jan 2012
    Posts
    3

    Thumbs down SOAP set_relationship with custom modules

    Hello, I'm using the SOAP API with sugar professional 6.3.0, and am trying to run set_relationship between the Accounts module and a custom module. I've defined the relationship between the two modules (custom one-to-many accounts). However, when I try to call set_relationship via SOAP, the apache error log shows the following:

    PHP Fatal error: Call to a member function add() on a non-object in /var/www/soap/SoapSugarUsers.php on line 1347

    The offending block of sugar code is: (the line with->add())
    if (!empty($key)) {
    $mod->load_relationship($key);
    $mod->$key->add($module2_id);
    return $error->get_soap_array();
    }

    Upon further inspection, it turns out that the load_relationship() function call does in fact fail, however the failure is ignored in this code.


    The data I'm passing in via the SOAP call is as follows:
    Running set relationship with { 'module1': 'Accounts',
    'module1_1d': '87183ff6-87b6-60a6-4d75-4e559394f422',
    'module2': 'TR001_Releases',
    'module2_id': 'a97346c3-bbb7-a3d5-f4f4-4e9778ce7a76'}


    I've been trying to figure this out for a while now, but am starting to question if this is even possible... So, my question, is it even possible to use SOAP to relate an Account to a entity in a custom module?

    Best Regards,
    -Dave

  2. #2
    jmertic is offline Sugar Community Manager
    Join Date
    Dec 2007
    Posts
    2,224

    Default Re: SOAP set_relationship with custom modules

    Quote Originally Posted by davec2 View Post
    Hello, I'm using the SOAP API with sugar professional 6.3.0, and am trying to run set_relationship between the Accounts module and a custom module. I've defined the relationship between the two modules (custom one-to-many accounts). However, when I try to call set_relationship via SOAP, the apache error log shows the following:

    PHP Fatal error: Call to a member function add() on a non-object in /var/www/soap/SoapSugarUsers.php on line 1347

    The offending block of sugar code is: (the line with->add())
    if (!empty($key)) {
    $mod->load_relationship($key);
    $mod->$key->add($module2_id);
    return $error->get_soap_array();
    }

    Upon further inspection, it turns out that the load_relationship() function call does in fact fail, however the failure is ignored in this code.


    The data I'm passing in via the SOAP call is as follows:
    Running set relationship with { 'module1': 'Accounts',
    'module1_1d': '87183ff6-87b6-60a6-4d75-4e559394f422',
    'module2': 'TR001_Releases',
    'module2_id': 'a97346c3-bbb7-a3d5-f4f4-4e9778ce7a76'}


    I've been trying to figure this out for a while now, but am starting to question if this is even possible... So, my question, is it even possible to use SOAP to relate an Account to a entity in a custom module?

    Best Regards,
    -Dave
    Yes, you just need to use the link field name rather than the relationship name of 'TR001_Releases'. Check out this blog post for more details:

    SugarCRM Developer Blog » Blog Archive » HOWTO: Dealing with set_relationship failures
    John Mertic
    Sugar Community Manager

  3. #3
    davec2 is offline Junior Member
    Join Date
    Jan 2012
    Posts
    3

    Default Re: SOAP set_relationship with custom modules

    I had actually found and read that, however it was inconsistent with what was actually running in the sugarcrm code...

    In particular, when I call the set_relationship function via the soap API call, it ends up calling the
    handle_set_relationship($set_relationship_value) function (in soap/SoapSugarUsers.php), which expects the [module1, module1_id, module2, module2_id] parameters in an array....

    In looking thru other parts of sugar code, I see a function
    function new_handle_set_relationship($module_name, $module_id, $link_field_name, $related_ids) {
    in soap/SoapHelperFunctions.php which has a prototype consistent with the parameters describe in the blog article...

    I suppose my next question is, why would it be calling the old function?

    Thanks,
    -Dave

  4. #4
    davec2 is offline Junior Member
    Join Date
    Jan 2012
    Posts
    3

    Default Re: SOAP set_relationship with custom modules

    Figured it out with some assistance from the folks at sugar...

    1) Using the right version of the API. All the sample code I looked at used the old soap API, when I should have been using V4 of the API. E.G. https://localhost/service/v4/soap.php?wsdl

    The details were here: Sugar DeveloperZone - SugarCRM Developer Documentation, Sugar Documentation


    2) I had to use the right link field name, which was not obvious, but could be found in Extension/modules/TR001_Releases/Ext/Vardefs/tr001_releases_accounts_TR001_Releases.php


    Once those two items got fixed, it worked great...

    hope this helps someone else out there...


    Regards,
    -Dave
    mike.smedley likes this.

  5. #5
    mike.smedley is offline Junior Member
    Join Date
    Nov 2011
    Posts
    9

    Default Re: SOAP set_relationship with custom modules

    Edited: Since I originally posted this message, I have figured it out. My 'relate' field was wrong, and yes, you must change the "right" link field name. In my case this was in the file: custom/Extension/modules/mymodulename/Ext/Vardefs/mymoduledef.php

    The key parts are in red:

    $dictionary["QB_AccountsReceivable"]["fields"]["qb_acco08ccunts_ida"] = array (
    'name' => 'qb_acco08ccunts_ida',
    'type' => 'link',
    'relationship' => 'qb_accountsreceivable_accounts',
    'source' => 'non-db',
    'reportable' => false,
    'side' => 'right',
    'vname' => 'LBL_QB_ACCOUNTSRECEIVABLE_ACCOUNTS_FROM_QB_ACCOUN TSRECEIVABLE_TITLE',
    );
    Last edited by mike.smedley; 2012-02-16 at 09:55 PM.

  6. #6
    mike.smedley is offline Junior Member
    Join Date
    Nov 2011
    Posts
    9

    Default Re: SOAP set_relationship with custom modules

    edited because this has been solved
    Last edited by mike.smedley; 2012-02-16 at 09:50 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 11
    Last Post: 2010-08-07, 08:03 PM
  2. SOAP set_relationship for n:1 custom modules
    By dvelguru in forum Developer Help
    Replies: 1
    Last Post: 2010-01-25, 09:54 AM
  3. need SOAP set_relationship help
    By darcy.rippon in forum Developer Help
    Replies: 5
    Last Post: 2009-02-02, 07:24 PM
  4. set_relationship via SOAP in 5.1
    By josh.sweeney in forum Developer Help
    Replies: 1
    Last Post: 2008-09-27, 12:20 AM
  5. SOAP set_relationship()
    By George in forum Developer Help
    Replies: 0
    Last Post: 2006-01-11, 10:51 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
  •