NetSuite API:更新自定义对象字段

时间:2016-01-14 18:16:51

标签: c# soap netsuite

我正在尝试更新自定义对象中的字段,但是当我这样做时,我收到错误java.lang.NullPointerException

在例外的Code对象中还有这个:http://schemas.xmlsoap.org/soap/envelope/:Server.userExceptionThis S/O thread表示我发送的请求可能有问题导致服务器抛出异常。但是什么?例外中没有细节。

据我所知,我正在关注“SuiteTalk(Web服务)平台指南”中的更新示例,除了这是一个“CustomRecord”而不是“Customer”,所以我不得不做一些更改

这是我帮助更新CustomRecords的方法。错误发生在我实际发出请求的最后一行:

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

}

1 个答案:

答案 0 :(得分:1)

我终于想通了,我还需要提供内部ID和RecordRef来指定对象的类型:

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

}