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 update record on netsuite platform?

I am trying to update a purchase order record in netsuite from my webservice request.

Instead of updating the record it adds a new record with same details of previous record.

For example i have added one record for an item with quantity 150, now i want to update this quantity to 200. when i done update operation observed that there is two records one with 150 and another with 200. Here is the code. Help me where i am doing wrong.


PurchaseOrder po=new PurchaseOrder();
RecordRef rf=new RecordRef();
rf.setInternalId("1683");
po.setEntity(rf);
Calendar trandate=Calendar.getInstance();

po.setTranDate(trandate);
po.setCurrencyName("USA");
RecordRef rf1=new RecordRef();
rf1.setName("Primary Purchase Order");
po.setCustomForm(rf1);

CustomFieldList cfl=new CustomFieldList();
CustomFieldRef[] cfr=new CustomFieldRef[3];
cfr[0]=new StringCustomFieldRef("5391","custbody23", "zy-vnd-103");
ListOrRecordRef listOrRecordRef1=new ListOrRecordRef();
listOrRecordRef1.setName("Transportation Method");
listOrRecordRef1.setInternalId("1");

ListOrRecordRef listOrRecordRef2=new ListOrRecordRef();
listOrRecordRef2.setName("Delivery Incoterm");
listOrRecordRef2.setInternalId("1");

cfr[1]=new MultiSelectCustomFieldRef("5392","custbody24",new ListOrRecordRef[]{listOrRecordRef1});
cfr[2]=new MultiSelectCustomFieldRef("5393","custbody25",new ListOrRecordRef[]{listOrRecordRef2});
cfl.setCustomField(cfr);
po.setCustomFieldList(cfl);
RecordRef rf2=new RecordRef();
rf2.setName("22:London");
rf2.setInternalId("10");
po.setLocation(rf2);
Double exchangeRate=1.0;
po.setExchangeRate(exchangeRate);
PurchaseOrderItemList poil=new PurchaseOrderItemList();
PurchaseOrderItem[] item=new PurchaseOrderItem[1];
item[0]=new PurchaseOrderItem();
RecordRef rf3=new RecordRef();
rf3.setName("ACC05");
rf3.setInternalId("1070");
item[0].setItem(rf3);
item[0].setRate("15.28");
double qty=50.0;
item[0].setQuantity(qty);
double amt=764.0;
item[0].setAmount(amt);
Calendar expectedReceiptDate=Calendar.getInstance();
expectedReceiptDate.add(Calendar.DATE,7);
item[0].setExpectedReceiptDate(expectedReceiptDate);
poil.setItem(item);
po.setItemList(poil);

po.setBillAddress("hi<br>unitedstates<br>CA");
po.setInternalId("6306");

WriteResponse writeRes = _port.update(po);

web-service x 19
netsuite x 18
Posted On : 2014-08-04 09:32:46.0
profile veera - anyforum.in veera
3220
up-rate
5
down-rate

Answers


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()));
}
}

Posted On : 2014-08-04 14:39:19
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
5
down-rate

Thankyou for your support.Internal id is unique for every record that´s why i am passing internal id of created record in netsuite(see above code--->po.setInternalId("6306")).there is no problem while iam creating records from webservice request to Netsuite.But problem with updating record only eventhough passing internalid it is adding new record.i have tried many ways to identify the issue but can´t get solution till now.

Posted On : 2014-08-04 14:53:09
Satisfied : 0 Yes  1 No
profile veera - anyforum.in veera
3220
Reply This Thread
up-rate
0
down-rate
Comments
Above thread has sample code to add and update the record added recently. you should try it first.
profile Rishi Kumar - anyforum.in Rishi Kumar
523  1882  50047
Posted On :2014-08-04 15:38:15.0
Leave a Comment

For Add or update using list i.e. addList and updateList operation,
visit here: addList and updateList in webservice on netsuite- Click Here

Posted On : 2014-08-04 16:18:39
Satisfied : 1 Yes  0 No
profile Garima Gupta - anyforum.in Garima Gupta
596129560202
Reply This Thread
up-rate
3
down-rate
Comments
I wanna update one record so no need to go to updateList, i tried update for customer it works fine.
profile veera - anyforum.in veera
32  2  0
Posted On :2014-08-04 16:44:52.0
Leave a Comment

Hi Rajat,
I have updated one customer information it works fine.but still having no idea why it not works for Purchase order.

Posted On : 2014-08-04 16:33:26
Satisfied : 1 Yes  0 No
profile veera - anyforum.in veera
3220
Reply This Thread
up-rate
0
down-rate
Comments
I think nothing differ in adding and updation. If you are doing addition successfully then set some different value and same externalId or internalId. and change add operation to update having rest code same.
profile Garima Gupta - anyforum.in Garima Gupta
596  1295  60202
Posted On :2014-08-05 00:01:37.0
Leave a Comment



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