我正在尝试使用V3 API在QuickBooks中创建新发票。我发票创建工作完美,但我无法设置3个自定义字段的值。
我需要一个在此上下文中使用AnyIntuitObject属性的VB或C#解析器。
以下是我尝试实施的代码:
Dim serviceContext As ServiceContext = getServiceContext(profile)
Dim invoiceDataService As New DataService(serviceContext)
Dim oInvoice As New Invoice()
oInvoice.DocNumber = "8675309"
oInvoice.TxnDate = DateTime.Today.Date
oInvoice.TxnDateSpecified = True
oInvoice.CustomerRef = New ReferenceType() With {.Value = "1885", .name = "QBT"}
Dim cField As New CustomField()
cField.DefinitionId = 1
cField.Name = "MyCustomFieldName"
cField.Type = CustomFieldTypeEnum.StringType
cField.AnyIntuitObject = New String() {"MyCustomFieldValue"}
oInvoice.CustomField = New CustomField() {cField}
Dim invLine As New Line()
invLine.Amount = 999.99D
invLine.AmountSpecified = True
invLine.DetailType = LineDetailTypeEnum.SalesItemLineDetail
invLine.DetailTypeSpecified = True
invLine.AnyIntuitObject = New SalesItemLineDetail With
{
.ItemElementName = ItemChoiceType.UnitPrice,
.AnyIntuitObject = 999.99D,
.Qty = 1D,
.ItemRef = New ReferenceType() With {.name = "Service", .Value = "529"}
}
oInvoice.Line = New Line() {invLine}
Dim invoiceAdded As Invoice = invoiceDataService.Add(Of Invoice)(oInvoice)
我已经查看了我可以找到的与自定义字段和API相关的每个帖子,但仍未找到解决方案。
非常感谢能提供的任何帮助!
答案 0 :(得分:2)
使用以下方法解决了该问题:
Dim customFieldList As New List(Of CustomField)
Dim cField As New CustomField()
cField.DefinitionId = 2
cField.Name = "Week ending"
cField.Type = CustomFieldTypeEnum.StringType
cField.AnyIntuitObject = inv.WeekEnding.ToString("MM/dd/yyyy")
customFieldList.Add(cField)
oInvoice.CustomField = customFieldList.ToArray