Wednesday, November 7, 2018

Sample PHP code in using Initialize in conjunction with Add operation in Web Services.

Below is a sample code in initializing a sales order to add an invoice transaction using the PHP toolkit.

// Create initializeRequest object
$initializeObject = new nsComplexObject("InitializeRecord");
$initializeObject->setFields(array("type"=>"invoice","reference"=>array("type"=>"salesOrder","internalId"=>$internalid)));

// Call initializeResponse
$initializeResponse = $myNSclient->initialize($initializeObject);
       
$myNSclient->setPreferences(true,false);
       
// Create Invoice object
$addInvoice = new nsComplexObject("Invoice");
$addInvoice->setFields($initializeResponse->record->getFields());
       
// Create Invoice record through add operation
$addResponse = $myNSclient->add($addInvoice);

if (!$addResponse->isSuccess) {           

    echo "<font color='red'><b>" . $addResponse->statusDetail[0]->message . "</b></font>";
               
    } else {
        echo "Successfully created invoice with internal ID ".$addResponse->recordRef->getField(internalId);           
}

No comments:

Post a Comment