Monday, April 15, 2019

Creating an Item Fulfillment from a Sales Order via Web Services Using PHP

Below is sample code on initializing an Item Fulfillment from a Sales Order. To process this you need a valid Login Session and an existing sales order that is waiting to be fulfilled.
Please note this sample will not work if you have Advanced Inventory Management Enabled.


require_once '../PHPToolkit/NetSuiteService.php';

// NetSuite Service Object
$service = new NetSuiteService();

// Internal Id of the existing sales order
$internalId= 414;
$initializeObject = new InitializeRecord();
$initializeObject->type = "itemFulfillment";
$initializeObject->reference = new InitializeRef();
$initializeObject->reference->type = "salesOrder";
$initializeObject->reference->internalId = $internalId;

// initialize the item fulfillment
$request = new InitializeRequest();
$request->initializeRecord = $initializeObject;
$initializeResponse = $service->initialize($request);

//If the initialize request is successful
if (!$initializeResponse->readResponse->status->isSuccess) {
echo "ADD ERROR";
} else {
echo "initialize SUCCESS
";

// Item fulfillment object
$fulfillment = new ItemFulfillment();
$fulfillment = $initializeResponse->readResponse->record;

//Passing the items from the sales order to item fulfillment
$ref = new RecordRef();
$ref->internalId = "1";
$fulfillment->itemList->item[0]->location = $ref;
$fulfillment->shipStatus = "_shipped";

// Adds the fulfillment into netsuite using the Service object.
$addrequest = new AddRequest();
$addrequest->record = $fulfillment;

$addResponse = $service->add($addrequest);

if (!$addResponse->writeResponse->status->isSuccess) {
print_r($addResponse);
} else {
echo "

";
echo "ADD SUCCESS, id " . $addResponse->writeResponse->baseRef->internalId;
echo "
";
}

}

2 comments:

  1. Thank you for the article. Do you know how this is done with advanced inventory enabled?

    ReplyDelete