AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



web-service-netsuite: How to perform add and update records using list on netsuite platform?

Provide java sample code to perform addList and updateList webservice operation.

web-service x 19
netsuite x 18
Posted On : 2014-07-01 15:23:12.0
profile Rishi Kumar - anyforum.in Rishi Kumar
523188245674
up-rate
5
down-rate

Answers


Let´s see first addList operation first. The addList operation is used to add one or more new instances of a record to NetSuite. If there are multiple records, they can either be of the same record type or different record types. For example, it?s possible to add a customer and a contact within a single request using this operation. However, each record entered must have a unique signature. The signature consists of parameters required to identify a record as unique.

For example, in the case of entities, a record is uniquely identified by its name, its type and its parent hierarchy. So you could have two records with the same entityId (or name) belonging to two different record types as follows:

Customer (the type):
John Smith
MyCompany: John Smith
Contact
John Smith
But a second record such as the following would be invalid:
Contact
John Smith

********** Java sample code for addList operation in webservice on netsuite Platform **********

public void addListCustomer() throws RemoteException {
this.login(true);
Customer cust1 = new Customer();
cust1.setEntityId("Shutter Fly");
cust1.setCompanyName("Shutter Fly, Inc");
cust1.setUnsubscribe(false);
Customer cust2 = new Customer();
cust2.setEntityId("GNC");
cust2.setCompanyName("GNC Corp");
cust2.setUnsubscribe(false);
Customer[] customers = new Customer[2];
customers[0] = cust1;
customers[1] = cust2;
WriteResponseList responseList = _port.addList(customers);
}


updateList:
----------------------------
The updateList operation is used to update one or more instances of a record type in NetSuite. If there are multiple records, they can either be of the same record type or different record types. For example, it?s possible to update a customer and a contact within a single request using this operation.
Only the fields that have been populated in each submitted record are updated in the system. If a field has not been populated, it is not updated in the system and it retains its previous value. If a field is set to an empty string, the previous value of the field is replaced with an empty string. 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:
---------------
Calculated and hidden fields in records are always updated by the system unless your service explicitly overrides the system values.


********** Java sample code for addList operation in webservice on netsuite Platform **********


public void updateCustomerList() throws RemoteException,
ExceededUsageLimitFault, UnexpectedErrorFault, InvalidSessionFault,
ExceededRecordCountFault {
// This operation requires a valid session
this.login(true);
// Prompt for list of nsKeys and put in an array
_console
.write("\nEnter nsKeys for customer records to be updated (separated by commas): ");
String reqKeys = _console.readLn();
String[] nsKeys = reqKeys.split(",");
// Create an array of Record objects to hold the customers
Record[] records = new Record[nsKeys.length];
// For each submitted nsKey, populate a customer object
for (int i = 0; i < nsKeys.length; i++) {
Customer customer = new Customer();
// Update name
customer.setEntityId("XYZ Inc " + i);
customer.setCompanyName("XYZ, Inc. " + i);
customer.setInternalId(nsKeys[i].trim());
records[i] = customer;
}
// Invoke updateList() operation to update customers
WriteResponseList responseList = _port.updateList(records);
// Process responses for all successful updates
WriteResponse[] responses = responseList.getWriteResponse();
boolean hasFailures = false;
_console.info("\nThe following customers were updated successfully:");
for (int i = 0; i < responses.length; i++) {
if ((responses[i] != null)
&& (responses[i].getStatus().isIsSuccess())) {
_console.info("\nCustomer[" + i + "]:");
_console.info("key="
+ ((RecordRef) responses[i].getBaseRef()).getInternalId()
+ "\nentityId="
+ ((Customer) records[i]).getEntityId()
+ "\ncompanyName="
+ ((Customer) records[i]).getCompanyName());
} else {
hasFailures = true;
}
}
// Process responses for all unsuccessful updates
if (hasFailures) {
_console.info("\nThe following customers were not updated:\n");
for (int i = 0; i < responses.length; i++) {
if ((responses[i] != null)
&& (!responses[i].getStatus().isIsSuccess())) {
_console.info("Customer[" + i + "]:");
_console.info("key="
+ ((RecordRef) responses[i].getBaseRef()).getInternalId());
_console.errorForRecord(getStatusDetails(responses[i]
.getStatus()));
}
}
}
}

Posted On : 2014-07-02 16:10:57
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129554550
Reply This Thread
up-rate
4
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in