0

After battling for getting more than 20 entries with get_entry_list, i'm now trying to use the SOAP API on SugarCRM 6.5 to set a relationship between two elements, created from a form on the user-land website.

The set_relationship method is described as following in the devs blog :

$response = set_relationship(session, module_name, module_id, link_field_name, related_ids, name_value_list, delete);

So here is the code which handles the request, assuming that another part of the code handles the security.

$values = array(    'id_frame' => $_POST['id_frame'],
                    'id_battery' => $_POST['id_battery'],
                    'reseller' => $_POST['reseller'],
                    'date_purchase' => $_POST['date_purchase'],
                    'products_versionning' => $_POST['product_purchased'],
                    'first_name' => $_POST['first_name'],
                    'last_name' => $_POST['name'],
                    'phone_home' => $_POST['phone'],
                    'email' => $_POST['email'],
                    'primary_address_street' => $_POST['address'],
                    'primary_address_street_2' => $_POST['address2'],
                    'primary_address_street_city' => $_POST['city'],
                    'primary_address_street_postalcode' => $_POST['zip'],

);

try{
    $prod_register = $soapClient->set_entry(
    $sessid,
    'myco_product_register',
    array(  array('name' => 'id_frame',                         'value' => $values['id_frame']),
            array('name' => 'id_battery',                       'value' => $values['id_battery']),
            array('name' => 'date_purchase',                    'value' => $values['date_purchase']),
            array('name' => 'first_name',                       'value' => $values['first_name']),
            array('name' => 'last_name',                        'value' => $values['last_name']),
            array('name' => 'phone_home',                       'value' => $values['phone_home']),
            array('name' => 'email',                            'value' => $values['email']),
            array('name' => 'primary_address_street',           'value' => $values['primary_address_street']),
            array('name' => 'primary_address_street_city',      'value' => $values['primary_address_street_city']),
            array('name' => 'primary_address_street_postalcode','value' => $values['primary_address_street_postalcode']),
            array('name' => 'description','value' => "Modèle : " . $values['products_versionning'] . "\nAcheté le " . $values['date_purchase'] . " à " . $values['reseller']),
        )
    );

    $client = $soapClient->set_entry(
    $sessid,
    'Accounts',
    array(  array('name' => 'name',                             'value' => $values['first_name'] . ' ' . $values['last_name']),
            array('name' => 'billing_address_street',           'value' => $values['primary_address_street']),
            array('name' => 'billing_address_city',             'value' => $values['primary_address_street_city']),
            array('name' => 'billing_address_postalcode',       'value' => $values['primary_address_street_postalcode']),
        )
    );

    $entry_id = $prod_register->id;

    $relationship_parameters = array(
        "module1" => "myco_product_register",
        "module1_id" => array($entry_id),
        "module2" => "myco_products_versionning",
        "module2_id" => array($values['products_versionning'])
    );


    //Now i'm setting the relationships
        $response = $soapClient->set_relationship($sessid, "myco_product_register", $entry_id,
                'myco_products_versionning_id_c', $values['products_versionning'], array(), 0);

        $response = $soapClient->set_relationship($sessid, "myco_product_register", $entry_id,
                'myco_resellers_id_c', $values['reseller'], array(), 0);

Both set_entry requests work and return a working id, but no one of the relationships work ($responses contains a failed equal to 1). So that's not a connection problem or such.

Talking about the relationships, one guy from the devblog said that

  • there has to be a relationship between the two modules
  • there has to be at least one related field in the module which handle the relation, whose name you can find in the module's vardefs.php

and i have

  • A One-to-one relationship between the product_register module and both products_versionning and resellers
  • A related field in product_register for each related module.

What may i be missing ?

Jivay
  • 1,034
  • 3
  • 10
  • 23

1 Answers1

0

try checking the log file of SugarCRM, you should find some mistakes. I used this API to create a relationship between Contacts and Accounts, and working properly. On the logs might find the answer to the problem.

    try {
        $result = $this->soapClient->set_relationship($this->sessionId,
                $accountModuleName, $accountId, $relationName, $contactsId);
        $this->doEvent(self::EVENT_WS_OPERATION_CALL);

        if ($result->created > 0 && $result->failed === 0) {
            return true;
        } else {
            return false;
        }
Popnoodles
  • 28,090
  • 2
  • 45
  • 53
Antonio Musarra
  • 370
  • 1
  • 14