我无法使用最新版本的.NET SDK和Quickbooks Online保存时间活动。我认为这是员工参考,但我无法解决它。 API是否正常工作?
DataService commonService = new DataService(serviceContext);
string displayName = "Test Customer";
displayName = displayName.Replace("'", "\\'"); //Escape special characters
QueryService<Customer> customerQueryServiceXX = new QueryService<Customer>(serviceContext);
Customer resultCustomer = customerQueryServiceXX.Where(m => m.DisplayName == displayName).FirstOrDefault();
string employeeName = "First Last";
employeeName = employeeName.Replace("'", "\\'"); //Escape special characters
QueryService<Employee> customerQueryServiceEE = new QueryService<Employee>(serviceContext);
Employee resultEmployee = customerQueryServiceEE.Where(m => m.DisplayName == employeeName).FirstOrDefault();
string sfasdfasdfasdf = resultEmployee.FamilyName;
TimeActivity timeActivity = new TimeActivity();
timeActivity.BillableStatus = BillableStatusEnum.Billable;
timeActivity.BillableStatusSpecified = true;
timeActivity.Hours = 8;
timeActivity.Minutes = 0;
timeActivity.TxnDate = DateTime.Now.Date;
timeActivity.TxnDateSpecified = true;
//timeActivity.HourlyRate = new decimal(200);
//timeActivity.HourlyRateSpecified = true;
timeActivity.NameOf = TimeActivityTypeEnum.Employee;
timeActivity.NameOfSpecified = true;
timeActivity.CustomerRef = new ReferenceType()
{
name = resultCustomer.DisplayName,
Value = resultCustomer.Id
};
timeActivity.ItemRef = new ReferenceType()
{
name = resultEmployee.DisplayName,
Value = resultEmployee.Id,
};
timeActivity.Description = "Did something";
TimeActivity timeActivityResult = commonService.Add(timeActivity);
答案 0 :(得分:1)
ItemRef用于提供服务项目。请使用timeActivity.AnyIntuitObject指定供应商或员工
timeActivity.NameOf = TimeActivityTypeEnum.Employee;
timeActivity.NameOfSpecified = true;
timeActivity.ItemElementName = ItemChoiceType5.EmployeeRef;
timeActivity.AnyIntuitObject= new ReferenceType()
{
name = resultEmployee.DisplayName,
Value = resultEmployee.Id,
};