2016-01-14 40 views
3

我正在嘗試更新自定義對象中的字段,但是當我這樣做時出現錯誤java.lang.NullPointerExceptionNetSuite API:更新自定義對象字段

在例外的代碼對象中也有這樣的:http://schemas.xmlsoap.org/soap/envelope/:Server.userExceptionThis S/O thread表明它可能是我發送的請求導致服務器拋出異常的問題。但是什麼?例外中沒有細節。

據我所見,我正在關注「SuiteTalk(Web服務)平臺指南」中的更新示例,除了這是一個「CustomRecord」而非「客戶」,所以我不得不做一些變化。

這是我必須幫助更新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); 

} 
+0

scriptId標識記錄類型。您還需要記錄實例的internalId。 – bknights

+0

@bknights謝謝,這讓我走上了正軌! – FirstDivision

回答

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

} 
相關問題