【问题标题】:NetSuite API: Update Custom Object FieldNetSuite API:更新自定义对象字段
【发布时间】:2016-01-14 18:16:50
【问题描述】:

我正在尝试更新自定义对象中的字段,但是当我这样做时收到错误 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);

}

【问题讨论】:

  • scriptId 标识记录类型。您还需要记录实例的 internalId。
  • @bknights 谢谢,这让我走上了正确的道路!

标签: c# soap netsuite


【解决方案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);

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-22
    • 1970-01-01
    • 2017-12-08
    相关资源
    最近更新 更多