Web services operations like add, addList, update, updateList, delete, and deleteList that can change data within a NetSuite account. Each record in NetSuite is uniquely identified by its record type in combination with either a system-generated NetSuite internal ID or an external ID that has been provided at the time of record creation or during an update.
Therefore, to perform an operation on an existing record, both the record type and either the internal ID or the external ID are required , and both are returned for each record in all operations on records.
Note:
----------------
Internal IDs are not reused in the system. Once an internal ID has been assigned, if the associated record is subsequently deleted, the ID is not reused.
External IDs can be updated through CSV or Web services. Therefore, it is recommended that your organization use a single approach for maintaining externalIds so that externalIds are not unknowingly updated using two separate methods. Although records of a particular type may be used in multiple integration scenarios, each record instance can only have a single external ID value. In order to maintain data integrity, only a single integrated application can set and update external ID values for each record type. External ID values for all records of a particular type must all come from the same external application.
Note:
------------------
Updating an externalId in Web services does not update its corresponding smbXML handle. You cannot copy the value of an external ID into an smbXML handle.
If you are using Web services for data migration where there may be fields that need to be populated that are unavailable during an add operation, you should perform two consecutive requests. Submit an initial add or addList request, with values for all fields available for an add operation, followed by an update or updateList request, with values for the fields available only during an update operation.
So I think all basic concept has been cleared from above discussion. Now i am giving you an example of add operation.
Add Operation:
---------------------------------
The add operation is used to add a new instance of a record in NetSuite. It is similar to the addList operation except that it allows only one record to be added at a time.
Note:
-------------------
Although records of a particular type may be used in multiple integration scenarios, each record instance can only have a single external ID value. In order to maintain data integrity, only a single integrated application can set and update external ID values for each record type. External ID values for all records of each type must all come from the same external application.
*****Following is the Java Sample code for add operation on netsuite platform by webservice *****
public void addCustomer() throws RemoteException, ExceededRecordCountFault,
ExceededUsageLimitFault, InsufficientPermissionFault, InvalidSessionFault {
// This operation requires a valid session
this.login(true);
Customer customer = new Customer();
// Set entityId, company name, and email
if ("true".equals(_properties.getProperty("promptForFieldValues"))) {
_console
.writeLn("\nPlease enter the following customer information. "
+ "Note that some fields have already been populated. ");
_console.write("Entity name: ");
customer.setEntityId(_console.readLn());
_console.write("Company name: ");
customer.setCompanyName(_console.readLn());
_console.write("E-mail: ");
customer.setEmail(_console.readLn());
} else {
customer.setEntityId("XYZ Inc");
customer.setCompanyName("XYZ, Inc.");
customer.setEmail("bsanders@yahoo.com");
}
// Set email preference.
customer.setEmailPreference(CustomerEmailPreference._hTML);
// Set entity status. The nsKey can be obtained from Setup > SFA >
// Customer Statuses.
// The default status is "Closed Won" which has an nsKey of 13
RecordRef status = new RecordRef();
if ("true".equals(_properties.getProperty("promptForFieldValues"))) {
_console.write("Entity status nsKey (press enter for default value of Closed Won): ");
String statusKey = _console.readLn();
if (statusKey.equals("")) {
status.setInternalId("13");
} else {
status.setInternalId(statusKey);
}
} else {
status.setInternalId("13");
}
customer.setEntityStatus(status);
// Populate the address list for this customer. You can put in as many
// adresses as you like.
CustomerAddressbook address = new CustomerAddressbook();
address.setDefaultShipping(Boolean.TRUE);
address.setDefaultBilling(Boolean.FALSE);
address.setLabel("Shipping Address");
address.setAddressee("William Sanders");
address.setAttention("William Sanders");
address.setAddr1("4765 Sunset Blvd");
address.setCity("San Francisco");
address.setState("CA");
address.setZip("94131");
address.setCountry(Country._unitedStates);
// Attach the CustomerAddressbookList to the customer
CustomerAddressbookList addressList = new CustomerAddressbookList();
CustomerAddressbook[] addresses = new CustomerAddressbook[1];
addresses[0] = address;
addressList.setAddressbook(addresses);
customer.setAddressbookList(addressList);
// Invoke add() operation
WriteResponse response = _port.add(customer);
// Print the document id from the SOAP header
// _console.info(
// "\nThe add() operation with document id " + _port.documentInfo.nsID +
// " was processed " );
// Process the response
if (response.getStatus().isIsSuccess()) {
_console.info("\nThe following customer was added successfully:"
+ "\nkey="
+ ((RecordRef) response.getBaseRef()).getInternalId()
+ "\nentityId="
+ customer.getEntityId()
+ "\ncompanyName="
+ customer.getCompanyName()
+ "\nemail="
+ customer.getEmail()
+ "\nstatusKey="
+ customer.getEntityStatus().getInternalId()
+ "\naddressbookList[0].label="
+ customer.getAddressbookList().getAddressbook(0)
.getLabel());
} else {
_console.error("The customer was not added:", true);
_console.error(getStatusDetails(response.getStatus()));
}
}
/***Following is the Java Sample code for update operation on netsuite platform by webservice ***/
public void updateCustomer() throws RemoteException,
ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault,
ExceededRecordCountFault {
// This operation requires a valid session
this.login(true);
Customer customer = new Customer();
// Get nsKey for update
_console.write("\nEnter nsKey for customer record to be updated : ");
customer.setInternalId(_console.readLn().toUpperCase());
// Set name and email
customer.setEntityId("XYZ 2 Inc");
customer.setCompanyName("XYZ 2, Inc.");
customer.setEmail("bsanders@xyz.com");
// Populate the address. Updating a list through WS results in the
// entire contents of the previous list being replaced by the new
// list.
CustomerAddressbook address = new CustomerAddressbook();
address.setDefaultBilling(Boolean.TRUE);
address.setDefaultShipping(Boolean.FALSE);
address.setLabel("Billing Address");
address.setAddr1("4765 Sunset Blvd");
address.setCity("San Mateo");
address.setState("CA");
address.setCountry(Country._unitedStates);
// Attach the address to the customer
CustomerAddressbookList addressList = new CustomerAddressbookList();
CustomerAddressbook[] addresses = new CustomerAddressbook[1];
addresses[0] = address;
addressList.setAddressbook(addresses);
customer.setAddressbookList(addressList);
// Invoke add() operation
WriteResponse response = _port.update(customer);
// Process the response
if (response.getStatus().isIsSuccess()) {
_console.info("\nThe following customer was updated successfully:"
+ "\nkey="
+ ((RecordRef) response.getBaseRef()).getInternalId()
+ "\nentityId="
+ customer.getEntityId()
+ "\ncompanyName="
+ customer.getCompanyName()
+ "\nemail="
+ customer.getEmail()
+ "\naddressbookList[0].label="
+ customer.getAddressbookList().getAddressbook(0)
.getLabel());
} else {
_console.error(getStatusDetails(response.getStatus()));
}
}
5