Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetSuite API: Update Custom Object Field

Tags:

c#

soap

netsuite

I am trying to update a field in a custom object, but when I do I get an error java.lang.NullPointerException.

There is also this in the Code object of the exception: http://schemas.xmlsoap.org/soap/envelope/:Server.userException. This S/O thread indicates it may be something wrong with the request I sent that caused the server to throw the exception. But what? There are no details in the exception.

As far as I can see I'm following the update example in "SuiteTalk (Web Services) Platform Guide" with the exception that this is a "CustomRecord" an not a "Customer", so I had to make some changes.

This is the method I have to help updating CustomRecords. The error happens in the final line where I actually make the request:

private static void UpdateCustomRecordValue(CustomRecord customRecord, string fieldName, string newValue, NetSuiteService netsuiteService)
{
    var field = customRecord.customFieldList.Where(custField => custField.scriptId == fieldName).FirstOrDefault();

    if (field == null) return;

    var updateRecord = new CustomRecord();
    updateRecord.scriptId = customRecord.scriptId;

    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
        new StringCustomFieldRef
        {
            value = newValue, 
            scriptId = field.scriptId
        }
    };

    updateRecord.customFieldList = custFieldList;
    var updateResponse = netsuiteService.update(updateRecord);

}
like image 593
FirstDivision Avatar asked Oct 19 '22 18:10

FirstDivision


1 Answers

I finally figured it out, I needed to also provide the internal ID and a RecordRef to specify the type of the object:

private static void UpdateCustomRecordValue(CustomRecord customRecord, string fieldName, string newValue, NetSuiteService netsuiteService)
{
    var field = customRecord.customFieldList.Where(custField => custField.scriptId == fieldName).FirstOrDefault();

    if (field == null) return;

    var updateRecord = new CustomRecord();

    updateRecord.recType = new RecordRef { 
        internalId = "56",  //<--  The same ID you would normally use to search with
        typeSpecified = true 
    };

    updateRecord.internalId = customRecord.internalId;

    CustomFieldRef[] custFieldList = new CustomFieldRef[] {
        new StringCustomFieldRef
        {
            value = newValue, 
            scriptId = field.scriptId, 
            internalId = field.internalId
        }
    };

    updateRecord.customFieldList = custFieldList;

    var updateResponse = netsuiteService.update(updateRecord);

}
like image 83
FirstDivision Avatar answered Nov 02 '22 23:11

FirstDivision