Sunday, September 16, 2018

Web Service > PHPToolkit > Entity Record> Delete Code Sample

As per the Suite Talk Web Services Platform Guide, the delete operation is used to delete an existing instance of a record in NetSuite. This example will guide developer how to perform a delete operation thru web service using PHPToolkit.

 

Note: This article requires existing knowledge of Web Services and PHP.


Note: The information contained in this article may or may not lead to the alteration of data in your production account, thus NetSuite holds no liability whether you choose to follow the instructions. In the event that data is deleted, altered or removed and requires restoration there will be applicable fees. Please proceed with caution.

 

Code snippet that deletes a contact record:

 

 

<?php

require_once 'PHPtoolkit.php';

require_once 'login_info.php';

global $myNSclient;

# DELETE CONTACT

# ===============

//when invoking a delete method it requires a baseRef parameter

$contactDelete = new nsRecordRef(array('type' => 'contact',

'internalId' => '1'));

//assign the result to a writeResponse to extract the result

$writeResponse = $myNSclient->delete($contactDelete);

try

{

if($writeResponse->isSuccess)

{

echo "Success deleted a contact record.";

}

else

{

//display the reason why the request fail

echo $writeResponse->statusDetail[0]->message;

}

}

catch (Exception $e)

{

echo "Unable to delete the contact due to the following error: " . $e;

exit();

}

?>

 

 

The above code generates the following SOAP request:

 

SOAP Request:

<Envelope>
    <Header />
    <Body>
        <delete>
            <baseRef type="RecordRef" type="contact" internalId="1"/>
        </delete>
    </Body>
</Envelope>


SOAP Response:

<Envelope>
    <Header>
        <documentInfo>
            <nsId>WEBSERVICES_TSTDRV570143_0202201018697293632015976746_1e59b7</nsId>
        </documentInfo>
    </Header>
    <Body>
        <deleteResponse>
            <writeResponse>
                <status isSuccess="true" />
                <baseRef type="RecordRef" type="contact" internalId="179" />
            </writeResponse>
        </deleteResponse>
    </Body>
</Envelope> 

No comments:

Post a Comment