It's possible that I'm doing something wrong but I really don't think I am.
I have a classic scenario where I want to validate line item values before allowing the line to commit.
The api functions are acting very strange. They seem to returning data from the PREVIOUS state of the line when it was last committed. For example, if I have a line with a "name" field and I do the following:[LIST]
[*]add new line and enter "dog" in the name field and click add
[*]edit this line and type "cat"
[*]The value of "name" in the OnValidate method will return "dog".[/LIST]It's validating validated data. Stupid.
Here is the code (it's not pretty, I just started working on it):
AddressViewClient.OnValidateLine = function AddressViewClient_onValidateLine(type) { // At this time we are only interested in the addressView lines if(type !== AddressView.SUBLIST_ID) { return; } // Check to make sure that certain required fields are not null or empty // and that generally all the data is clean and valid. var reqFlds = [ [MakeFldId(ADDR_LIST_FLD.LABEL), 'Label'], [MakeFldId(ADDR_LIST_FLD.ADDRESSEE), 'Addressee'], [MakeFldId(ADDR_LIST_FLD.ADDR1), 'Address Line 1'], [MakeFldId(ADDR_LIST_FLD.CITY), 'City'], [MakeFldId(ADDR_LIST_FLD.STATE), 'State'], [MakeFldId(ADDR_LIST_FLD.ZIP), 'Zip'] ]; var msgBuff = ['Please enter a value for the following fields:']; var val; var lineNum = nlapiGetCurrentLineItemIndex(AddressView.SUBLIST_ID); var isOk = true; for(var i = 0, len = reqFlds.length; i < len; i++) { val = nlapiGetLineItemValue(AddressView.SUBLIST_ID, reqFlds[i][0], lineNum); if( IsNullOrEmpty(val) ) { isOk = false; msgBuff.push( reqFlds[i][1] ); } } if(isOk === false) { alert(msgBuff.join('n')); } return isOk; }