Skip to content

Need a Intacct.SDK.Functions.AccountsPayable.BillCreate Example #257

@smunk-varis

Description

@smunk-varis

I need help submitting a AP Bill Item using Intacct.SDK.Functions.AccountsPayable.BillCreate.

The following is my AP Submission method:

    public bool ApSubmission()
    {
      bool returnValue = false;

      try
      {
        // Reference: https://developer.intacct.com/api/accounts-payable/bills/#create-bill

        // Create an OnlineClient object using established credentials.
        OnlineClient sageClient = SageClient();

        // Create the RequestConfig object.
        RequestConfig requestConfig = new RequestConfig()
        {
          ControlId = $"{Guid.NewGuid()}"
        };

        // Create the Intacct.SDK.Functions.AccountsPayable.BillCreate object.
        Intacct.SDK.Functions.AccountsPayable.BillCreate createBill = new Intacct.SDK.Functions.AccountsPayable.BillCreate()
        {
          VendorId = "V2292"
         ,DueDate = DateTime.Now.AddDays(90)
         ,PaymentTerm = "N30"
         ,Action = "Submit"
         ,AttachmentsId = "0000"
         ,BillNumber = "0000"
         //,CustomFields = 
         ,ControlId = $"TEST_{Guid.NewGuid()}"
         ,ExternalId = "0000"
         ,OnHold = false
         ,Description = "Test invoice"
         ,PayToContactName = "JDoe"
         ,ReturnToContactName = "nbodie"
         ,BaseCurrency = "USD"
         ,TransactionCurrency = "USD"
         ,TransactionDate = DateTime.Now
         ,ExchangeRateDate = DateTime.Now
         ,ExchangeRateType = "Intacct Daily Rate"
         ,ExchangeRateValue = 0
         ,DoNotPostToGL = false
         ,GlPostingDate = DateTime.Now
         ,ReferenceNumber = "X0000"
         ,SummaryRecordNo = 0
         ,Lines = new List<Intacct.SDK.Functions.AccountsPayable.AbstractBillLine>()
        };

        // Create a billing line item.
        createBill.Lines.Add(new SageBillLine()
        {
          GlAccountNumber = "TEST0000"
         ,OffsetGlAccountNumber = "0000"
         ,TransactionAmount = 1005
         ,Memo = "TEST ITEM"
         ,LocationId = "DEV"
         ,DepartmentId = "MR"
         ,TotalPaid = 0
         ,TotalDue = 1005
         ,ProjectId = "CopyCharge"
         ,CustomerId = "TEST"
         ,VendorId = "V2292"
         ,EmployeeId = "CRASHDUMMY"
         ,ItemId = "0000"
         ,ClassId = "0000"
         ,ContractId = "0000"
         ,WarehouseId = "0000"
         ,Billable = true
         ,AccountLabel = "TEST"
         ,Form1099 = true
         ,AllocationId = "0000"
         ,TaskId = "0000"
         ,Key = 0
          //,CustomFields
        });

        // Execute the bill submission.
        Task<Intacct.SDK.Xml.OnlineResponse> clientTask = sageClient.Execute(createBill, requestConfig);
        clientTask.Wait();
        Intacct.SDK.Xml.OnlineResponse taskResponse = clientTask.Result;

        // This line is inserted as a debug break-point target.
        int z = 0;
        ////taskResponse.
      }
      catch (Exception ex)
      {
        Dictionary<string, string> additionalInfo = new Dictionary<string, string>();
        additionalInfo.Add("StackTrace", ex.StackTrace);

        Log.LogSQLEvent(VARISConst.Workflow.ServiceNamespace, $"Sage ApSubmission failure. {ex.Message}", 1, additionalInfo);
      }

      return returnValue;
    }

With the createBill.Lines.Add block in place, I get this error on sageClient.Execute:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Varis.WinService.Workflow.Sage.ApSubmission() in C:\Users\smunk\source\repos\WinServices\Service.Workflow\Varis.WinService.Workflow\Sage.cs:line 162

  This exception was originally thrown at this call stack:
    Intacct.SDK.Functions.AccountsPayable.BillCreate.WriteXml(ref Intacct.SDK.Xml.IaXmlWriter)
    Intacct.SDK.Xml.Request.OperationBlock.WriteXml(ref Intacct.SDK.Xml.IaXmlWriter)
    Intacct.SDK.Xml.RequestBlock.WriteXml()
    Intacct.SDK.Xml.RequestHandler.ExecuteOnline(System.Collections.Generic.List<Intacct.SDK.Functions.IFunction>)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Intacct.SDK.AbstractClient.ExecuteOnlineRequest(System.Collections.Generic.List<Intacct.SDK.Functions.IFunction>, Intacct.SDK.RequestConfig)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Intacct.SDK.OnlineClient.Execute(Intacct.SDK.Functions.IFunction, Intacct.SDK.RequestConfig)

Inner Exception 1:
InvalidCastException: Unable to cast object of type 'Varis.WinService.Workflow.SageBillLine' to type 'Intacct.SDK.Functions.AccountsPayable.BillLineCreate'.

With the createBill.Lines.Add block commented out, I get this error on sageClient.Execute:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at Varis.WinService.Workflow.Sage.ApSubmission() in C:\Users\smunk\source\repos\WinServices\Service.Workflow\Varis.WinService.Workflow\Sage.cs:line 168

  This exception was originally thrown at this call stack:
    Intacct.SDK.Xml.AbstractResponse.AbstractResponse(System.IO.Stream)
    Intacct.SDK.Xml.OnlineResponse.OnlineResponse(System.IO.Stream)
    Intacct.SDK.Xml.RequestHandler.ExecuteOnline(System.Collections.Generic.List<Intacct.SDK.Functions.IFunction>)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Intacct.SDK.AbstractClient.ExecuteOnlineRequest(System.Collections.Generic.List<Intacct.SDK.Functions.IFunction>, Intacct.SDK.RequestConfig)
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
    Intacct.SDK.OnlineClient.Execute(Intacct.SDK.Functions.IFunction, Intacct.SDK.RequestConfig)

Inner Exception 1:
ResponseException: Response control status failure - XL03000003 XML Parse schema error: Error 1871: Element 'billitems': Missing child element(s). Expected is ( lineitem ).. Line: 1, column: 0. [Support ID: X8jNrWEB030%7EZ0d7SP5r0Xu4hRz-2oy8UAAAABE]

I am able to establish the OnlineClient object and pull vendor lists. So, I am confident the OnlineClient object part is working properly.

I would be grateful for any suggestions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions