NetSuite API:更新自定义对象字段
NetSuite API: Update Custom Object Field
我正在尝试更新自定义对象中的字段,但是当我这样做时出现错误 java.lang.NullPointerException
。
异常的Code对象中也有这个:http://schemas.xmlsoap.org/soap/envelope/:Server.userException
。 This S/O thread表示可能是我发送的请求有问题导致服务器抛出异常。但是什么?异常中没有详细信息。
据我所知,我正在遵循 "SuiteTalk (Web Services) Platform Guide" 中的更新示例,除了这是 "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);
}
我终于想通了,我还需要提供内部 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);
}
我正在尝试更新自定义对象中的字段,但是当我这样做时出现错误 java.lang.NullPointerException
。
异常的Code对象中也有这个:http://schemas.xmlsoap.org/soap/envelope/:Server.userException
。 This S/O thread表示可能是我发送的请求有问题导致服务器抛出异常。但是什么?异常中没有详细信息。
据我所知,我正在遵循 "SuiteTalk (Web Services) Platform Guide" 中的更新示例,除了这是 "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);
}
我终于想通了,我还需要提供内部 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);
}