skip to Main Content

I’m attempting to close a Sales Order using the following code:

<?php
$request = new GetRequest();
$request->baseRef = new RecordRef();
$request->baseRef->internalId = $internal_id;
$request->baseRef->type = "salesOrder";
$getResponse = $service->get($request);

if (!$getResponse->readResponse->status->isSuccess) {
    $this->updateTaskStatus($task_id, 'error');
    $error = "Failed to close order, error message: ";
    $error .= print_r($getResponse->readResponse->status->statusDetail, true);

    $result = array("succeeded" => false, "error" => $error, "task_id" => $task_id, "so_id" => $internal_id);

    return $result;
} else {
    $initial_so = $getResponse->readResponse->record;

    $so = new SalesOrder();
    $so->internalId  = $internal_id;

    $so->orderStatus = SalesOrderOrderStatus::_closed;
    $so->itemList = new SalesOrderItemList();

    foreach($initial_so->itemList->item as $item) {
        $item->isClosed = true;
        $so->itemList->item[] = $item;
    }

    $so->itemList->replaceAll = false;

    $updateRequest = new UpdateRequest();
    $updateRequest->record = $so;

    $updateResponse = $service->update($updateRequest);

    if(!$updateResponse->writeResponse->status->isSuccess) {
        $this->updateTaskStatus($task_id, 'error');
        $error = "Failed to close order, error message: ";
        $error .= print_r($updateResponse->writeResponse->status->statusDetail, true);

        $result = array("succeeded" => false, "error" => $error, "task_id" => $task_id, "so_id" => $internal_id);

        return $result;
    } else {
        $result = array("succeeded" => true, "msg" => "Successfully closed order.");
        
        return $result;
    }
}

I initially just tried to close the sales order by updating the status but received the Invalid orderstatus reference key H error.

Some searching leads me to believe this was because I was not closing the items as well, so now I am closing the items by setting $item->isClosed = true; as shown above.

This results in the same Invalid orderstatus reference key H error so I’m unsure of what more is needed to close this order.

2

Answers


  1. To close sales orders you have to close them on the line level.

    There is a column called closed ( id : isClosed if i can recall ) , you need to close all the lines in order to close a sales order.

    Login or Signup to reply.
  2. Closing all the (open) order lines is sufficient. When all lines are closed, NetSuite automatically updates the Status.

    See below from SuiteAnswers 29086.


    Scenario

    A user wants to set the Status field of Sales Order to Closed using Web Services.

    Solution

    To close a Sales Order via Web Services, set the isClosed field on each of the line item to true instead of changing the orderStatus field to _closed. Do the same procedure on a User Event script.

    Here is a sample Web Service request for closing a Sales Order using the isClosed field in the line item:

    <soapenv:Body>
       <update xsi:type='platformMsgs:UpdateRequest'>
          <record xsi:type='tranSales:SalesOrder' internalId='3735'>
             <itemList xsi:type='tranSales:SalesOrderItemList'>
                 <item xsi:type='tranSales:SalesOrderItem'>
                         <isClosed xsi:type='xsd:boolean'>true</isClosed>
                     <line xsi:type='xsd:long'>1</line>
                 </item>
             </itemList>
          </record>
       </update>
    </soapenv:Body>
    

    Note: The line field specifies the line number of the item as seen in the User Interface (always starts with 1).

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search