PoorBob PoorBob - 2 months ago 8
Java Question

Netsuite get value of custom field Java

I have a SalesOrder object that I casted from a ReadResponse like this:

SalesOrder salesOrder = ((SalesOrder) response.getRecord());

How can I access the value of customfields within the individual line items attached to the SalesOrder object?

I have this so far, and it would work perfectly if the value I needed was a regular field:

for(SalesOrderItem item: salesOrder.getItemList().getItem()){

I also have access to the names/internalIDs of all custom field associated with the line item like this:

for(CustomFieldRef field: item.getCustomFieldList().getCustomField()){
_console.info(field.getScriptId() + " : " + field.getInternalId());

How do I use these to return values? Or am I not on the right path at all?


The issue was I had to cast the field to the appropriate "Custom Field" type in order to access a "getValue()" function. Like this:

        //loop through custom fields for custom field data.
        for(SearchColumnCustomField field: fieldArray){
            //_console.writeLn(field.getInternalId() + " " + field.getScriptId());

            //Then we are at the [Custom Field internalId: 1855].
            if (field.getInternalId().equals("1855")){
                SearchColumnStringCustomField searchBodyField = (SearchColumnStringCustomField)field;
                couponCode = searchBodyField.getSearchValue();
            //Then we are at the [Custom Field internalId: 681]
            if (field.getInternalId().equals("681")){
                SearchColumnStringCustomField searchBodyField = (SearchColumnStringCustomField)field;
                orderId = searchBodyField.getSearchValue();