无法与SuiteCRM / SugarCRM CE中的联系和机会相关联

时间:2015-04-17 02:44:24

标签: rest sugarcrm suitecrm sugarbean

我正在编写一个脚本,将数据导入SuiteCRM / SugarCRM CE。我需要创建一个联系人和一个机会。然后,我需要将两者联系起来。

我在联系人和机会之间有很多关系。每个联系人都应该能够创造多个机会。每个机会都应该能够分配给多个联系人。

当我运行代码时,它会显示“1个创建的关系”,但当我检查套件时,联系人或机会子面板下没有列出任何内容。

仅供参考,我将机会模块“Gigs”重新命名为使用此API包装器:github.com/asakusuma/SugarCRM-REST-API-Wrapper-Class

以下是代码:

<?php

// Load Composer Dependencies for Sugar API Wrapper
require_once('vendor/autoload.php');

// Create Sugar Object
$sugar = new \Asakusuma\SugarWrapper\Rest;

// Set Sugar Connection Items
$sugar->setUrl('https://example.com/suitecrm/service/v2/rest.php');
$sugar->setUsername('User');
$sugar->setPassword('Pass');

// Connect to Sugar 
$sugar->connect();

// Did something go wrong with the connection? Report it. 
$error = $sugar->get_error();

if($error !== FALSE) {
    return $error['name'];
}
// Ok... We're going to try and create a test entry in Sugar/Suite

// Create a Contact
$modules = 'Contacts';

// Set Values
$values = array(
    'contact_type_c' => 'Prospect',
    'lead_source' => 'Website',
    'first_name' => 'Test',
    'last_name' => 'Contact',
    'phone_mobile' => '(123) 456-7890',
    'email1' => 'test@test.com'
    );

// Put it in Suite
$result = $sugar->set($modules, $values);

$contactID = $result['id'];

// Ok, now let's create a Opportunity
$modules = "Opportunities";

$values = array(
    'name' => 'My Test Gig',
    'sales_stage' => 'New Inquiry',
    'amount' => '400'
);

$result = $sugar->set($modules, $values);

$gigID = $result['id'];

// Lastly, let's relate the two - HERE'S WHERE I HAVE PROBLEMS!

// Set Relationship
$moduleName = 'Contacts';
$moduleID = $contactID;
$linkFieldName = 'opportunities';
$relatedIDs = array($gigID);
$nameValueList = array(); // Passing empty array because we don't have any fields that need it
$delete = 0;

$result = $sugar->set_relationship($moduleName, $moduleID, $linkFieldName, $relatedIDs, $nameValueList, $delete);

echo $result['created'] . " relationship(s) made";

?>

联系人和机会创建得很好。这是没有发生的关系。

1 个答案:

答案 0 :(得分:0)

呃......好吧,我明白了。

我查看了API文档,并将$ relatedIDs作为数组传回。我没有意识到的是API也是这样做的。所以传递给Suite的是多维数组而不是单个数组。