Wednesday, August 31, 2011

NetSuite Fact 1: nlapiSubmitField() doesn't work on ALL fields

We've MOVED!!!! www.codeboxllc.com/ksc


Five days ago, I was inspired by the growing list of cases currently assigned to me. Did I say inspired? I meant to say annoyed. There was one case in particular that was marked urgent and needed to be done by the end of the month. (That was five days ago)

It was a simple task yet so important. Update Department and Class field on Transaction records; specifically Sales Order, Cash Sales and Invoices.

Obvious weapon of choice was Scheduled Job and this was the task that helped me realize the power of Script Parameter. My choice for SuiteScript API function to update these two fields was nlapiSubmitField(). Why? It costs less (About 20 Governance to load and submit vs 10 to update fields).

I finished my coding in approximately 45 mins. Felt proud and clever so I gave myself a pad on the back. I began testing my code and something odd occurred. Even after nlapiSubmitField was called, my fields weren't updated!

I thought it was a defect so I tried using the function against other fields such as custom fields and native fields. It worked just fine. It JUST didn't work for Department and Class fields on Transaction record types.

This was my code:
var flds=['department','class'];
var vals=[19,51]; //internal ID of department and class
var rectype='salesorder';
var recid=555; //internal ID of sales order record
nlapiSubmitField(rectype, recid, flds,vals);
After testing out the function against other native records such as Customer record type, I called NetSuite Support and asked about it.  The support rep. told me that there is an existing defect out there for nlapiSubmitField API call in v2011.2. The problem was, I WASN'T!

I get a response from Support Rep the next day saying this:
Upon further investigation, it appears that the Department and Class fields in the Sales order record are both "non-direct list editable", the nlapiSubmitField in this case behaves as designed. The nlapiSubmitField function will only work for fields which can be Direct List Edited. You can see this on the help guide. Here is the path: SuiteFlex (Customization, Scripting, and WebServices) > SuiteScript > Scripting Records, Fields, Forms, and Sublists > Direct List Editing and SuiteScript > Direct List Editing Using nlapiSubmitField
My problem with this response from the support rep. is that no where on that Help section does it say that Department and Class fields are categorized as None-Direct list editable.

However, if you go to SuiteFlex (Customization, Scripting, and Web Services) : SuiteScript : Scripting Records, Fields, Forms, and Sublists : Direct List Editing and SuiteScript : Direct List Editing and SuiteScript Overview it DOES state this:
In SuiteScript, you cannot direct list edit select fields. In other words, you cannot call nlapiSubmitField on a select field.
If you look at Department and Class field in SuiteScript Recrods Browser both are indeed labeled as select fields.  What's MORE interesting is that I have used nlapiSubmitField function to set select fields!!!!!!!!!

If you are having this problem, you are not the only one. If you want to set Department and Class fields on a transaction record such as Sales Order, you will need to do it the old fashion way:
var soid='123';
var deptid='19';
var clsid='51';
var so=nlapiLoadRecord(rectype, trid);
so.setFieldValue('department',deptid);
so.setFieldValue('class',clsid);
nlapiSubmitRecord(so);
My thought is NetSuite should update their documentation to provide Non-Direct editable fields list.

No comments:

Post a Comment