任何人都知道如何通过 Sugar 的 REST API v4 从表单中的多选输入中插入多个值。我还没有找到任何关于此的文档。以下正确插入 1 个值,但我坚持保存多个值:
function getSugar($method, $parameters){
$url = 'https://****.sugarondemand.com/service/v4/rest.php';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$json = json_encode($parameters);
$postArgs = array(
'method' => $method,
'input_type' => 'JSON',
'response_type' => 'JSON',
'rest_data' => $json
);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postArgs);
$response = curl_exec($curl);
if (!$response) {
die("Connection Failure.\n");
}
$result = json_decode($response);
if ( !is_object($result) ) {
die("Error handling result.\n");
}
if($method == "set_entry" || $method == "login"){
if ( !isset($result->id) ) {
die("Error: {$result->name} - {$result->description}\n.");
}
$id = $result->id;
return $id;
}else{
if ( !is_object($result) ) {
var_dump($response);
die("Error handling result.\n");
}
return true;
}
}
$x = "ABC";
$parameters = array(
'session' => $sessionId,
'module' => 'Leads',
'name_value_list' => array(
array('name' => 'programs_c', 'value' => $x),
),
);
$method = "set_entry";
$leadID = getSugar($method, $parameters);
字段“programs_c”是 Sugar 中的自定义多选字段,具有多个下拉值。我试过运行一个 for-each 循环,但只插入最后一个值。我还尝试了几乎所有可能的在数组中插入数组的变体,但没有任何成功。任何帮助深表感谢!我花了几个小时试图弄清楚这一点。在此先感谢您提供有关如何处理此问题的任何见解/方向。