Anyone have knowledge on how to insert multiple value from a multiselect input in a form via sugar's REST API v4. I haven't found any documentation on this. The following inserts 1 value correctly but I'm stuck on saving multiple values:
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);
The field "programs_c" is a custom multiselect field in sugar with several dropdown values. I've tried running a for-each loop but that only inserts the last value. I've also attempted nearly every possible variation of inserting an array within the array without any success. Any help is much appreciated! I've spent hours trying to figure this out. Thanks in advance for any insight / direction on how to handle this.
Does putting the field contents in this format work?
^value1^,^value2^,^value3^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With