1. Call get method to retrieve the current values on the custom list
2. Create a new array that will store the new values that you will add and assigned it on the "value" of CustomListCustomValue object
3. Update the current custom list by inserting the new array values from step 2 using array_merge function
4. Call update method to update the custom list.
<?php
require_once '../PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
//call get method to retrieve the current values on the custom list
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = "67";
$request->baseRef->type = "customList";
$getResponse = $service->get($request);
//use for loop to retrieve the current values inside the custom list
$my_custom_lists[] = $getResponse->readResponse->record->customValueList;
for ($mycust = 0; $mycust < count($my_custom_lists); $mycust++)
{
$my_custom_value_obj[$mycust] = $my_custom_lists[$mycust]->customValue;
}
//create a new array that will contain the new values to be added on custom list
$new_custom_list_values = array('New Value g', 'New Value h');
for ($val = 0; $val <= count($new_custom_list_values); $val++)
{
$new_custom_value_obj[$val] = new CustomListCustomValue();
$new_custom_value_obj[$val]->value = $new_custom_list_values[$val];
}
//combine the current and new values of the custom list
$merge_custom_value_list = array_merge($my_custom_value_obj[0],$new_custom_value_obj);
//call update operation to add the values of the custom list
$new_custom_value_list = new CustomListCustomValueList();
$new_custom_value_list->customValue = $merge_custom_value_list;
$custom_list = new CustomList();
$custom_list->internalId = 67;
$custom_list->replaceAll = false;
$custom_list->customValueList = $new_custom_value_list;
$request = new UpdateRequest();
$request->record = $custom_list;
$updateResponse = $service->update($request);
if (!$updateResponse->writeResponse->status->isSuccess) {
echo "UPDATE CUSTOM LIST ERROR";
exit();
} else {
echo "UPDATE CUSTOM LIST SUCCESS, id " . $updateResponse->writeResponse->baseRef->internalId;
}
?>
No comments:
Post a Comment