1

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

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

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

仅供参考,我将 Opportunities 模块重命名为“Gigs”并使用此 API Wrapper: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";

?>

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

4

1 回答 1

0

呃……好吧,我明白了。

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

于 2015-04-17T06:07:39.807 回答