Sage / SData-2.0

Contains documents pertaining to the SData 2.0 developments
33 stars 10 forks source link

Unable to Create Sales Invoice #136

Closed mbharanidharan88 closed 5 years ago

mbharanidharan88 commented 5 years ago

I am trying to Create Sales Invoice but running up with the below error which is generic. Any ideas to trace this up, please?

POST operation failed - Exception has been thrown by the target of an invocation.

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck) at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark) at System.Activator.CreateInstance[T]() at Sage.Common.Metadata.RuntimeObjectXmlReader.ReadReferenceElement[S,T](XmlReader reader, T component, ISerializationSettings settings) at ObjectXmlReaderb0e474d430024142b8fc23f24ab0477d.dll.ReadElement(XmlReader , Object , Int32 , ISerializationSettings ) at Sage.Common.Metadata.RuntimeObjectXmlReader.ReadReference[T](XmlReader reader, T component, String name, ISerializationSettings settings) at ObjectXmlReaderb0e474d430024142b8fc23f24ab0477d.dll.Deserialize(XmlReader , Object , String , ISerializationSettings ) at Sage.Common.Metadata.RuntimeObjectXmlReader.ReadReferenceElement[S,T](XmlReader reader, T component, ISerializationSettings settings) at ObjectXmlReader11a17dad3fdc4dd095a197f9bc8dbf23.dll.ReadElement(XmlReader , Object , Int32 , ISerializationSettings ) at Sage.Common.Metadata.RuntimeObjectXmlReader.ReadReference[T](XmlReader reader, T component, String name, ISerializationSettings settings) at ObjectXmlReader11a17dad3fdc4dd095a197f9bc8dbf23.dll.Deserialize(XmlReader , Object , String , ISerializationSettings ) at Sage.Common.Metadata.RuntimeObjectXmlReader.Deserialize(XmlReader reader, Object component, String name) at Sage.Common.Syndication.FeedSerializer.LoadFromStream[T](T feedEntry, Stream stream, ISerializationSettings settings, String assemblyFileLocation) at Sage.Common.Syndication.FeedSerializer.LoadFromStream[T](T feedEntry, Stream stream, ISerializationSettings settings) at RuntimeRequestHandlerc507396b0fb34237a49b824e6e7876a6.LoadFeedEntryFromStream(IFeedSerializer , FeedEntry , Stream ) at Sage.Integration.Accounts50.SDOAdapter.RequestHandler2.OnPostRequest(IRequest request) at Sage.Integration.Accounts50.SDOAdapter.RequestHandler2.PostRequest(IRequest request) at Sage.Integration.Accounts50.SDOAdapter.SDORequestManager.PostRequest(IRequest request) (-1)

Code:

Here the tradingAccount and the taxCode both have value.

        var salesInvoice = new salesInvoiceFeedEntry
        {
            tradingAccount = GetCustomer()
        };

        //Get Tax Code
        taxCodeFeedEntry taxCode = GetTaxCode();

        taxCodeFeedEntry taxReference = new taxCodeFeedEntry
        {
            UUID = taxCode.UUID
        };

        salesInvoice.taxCodes = new taxCodeFeed();
        salesInvoice.taxCodes.Entries.Add(taxReference);

        salesInvoice.carrierNetPrice = 80;
        salesInvoice.carrierTaxPrice = 20;
        salesInvoice.carrierTotalPrice = 100;
        salesInvoice.currency = "EUR";

        salesInvoiceLineFeedEntry invoiceLine = new salesInvoiceLineFeedEntry
        {
            type = "Standard",
            text = "Routine Maintenance",
            quantity = 2,
            netTotal = 50,
            taxTotal = 10,
            grossTotal = 60,
            taxCodes = new taxCodeFeed()
        };

        invoiceLine.taxCodes.Entries.Add(taxReference);

        salesInvoice.salesInvoiceLines = new salesInvoiceLineFeed();
        salesInvoice.salesInvoiceLines.Entries.Add(invoiceLine);

        SDataUri salesInvoiceUri = new SDataUri(SDATA_URI);

        salesInvoiceUri.CollectionType = "salesInvoices";

        var invoiceRequest = new SDataRequest(salesInvoiceUri.Uri, salesInvoice, Sage.Integration.Messaging.Model.RequestVerb.POST);

        invoiceRequest.Username = "MANAGER";
        invoiceRequest.Password = "";

        salesInvoiceFeedEntry savedSalesInvoice = new salesInvoiceFeedEntry();
        invoiceRequest.RequestFeedEntry<salesInvoiceFeedEntry>(savedSalesInvoice);

        if (invoiceRequest.IsStatusValidForVerb)
        {
            Console.WriteLine("Invoice Created Successfully");
        }
        else
        {
            Console.WriteLine("Failed");
        }
darroncockram commented 5 years ago

Nothing obvious leaps out as a problem but here's a working example: https://github.com/darroncockram/sdatasamples/tree/master/CreateSalesInvoice

mbharanidharan88 commented 5 years ago

Thanks! I referred the same and created the Invoice but still that error. Is there a way to get a Stack Trace with the request?

darroncockram commented 5 years ago

That is the stack trace in the error response but all it really tells us is that there was a problem deserialising the XML. If you capture the XML of the POST request what does it look like?

mbharanidharan88 commented 5 years ago
<?xml version="1.0" encoding="utf-8"?>
<entry xmlns:atom="http://www.w3.org/2005/Atom" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:cf="http://www.microsoft.com/schemas/rss/core/2005" xmlns="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:sme="http://schemas.sage.com/sdata/sme/2007" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:sdata="http://schemas.sage.com/sdata/2008/1" xmlns:http="http://schemas.sage.com/sdata/http/2008/1" xmlns:sdatasync="http://schemas.sage.com/sdata/sync/2008/1">
  <author />
  <sdata:payload>
    <salesInvoice sdata:uuid="00000000-0000-0000-0000-000000000000" xmlns="http://schemas.sage.com/crmErp/2008">
      <active xsi:nil="true" />
      <reference xsi:nil="true" />
      <reference2 xsi:nil="true" />
      <status xsi:nil="true" />
      <allocationStatus xsi:nil="true" />
      <deliveryStatus xsi:nil="true" />
      <statusFlag xsi:nil="true" />
      <statusFlagText xsi:nil="true" />
      <type xsi:nil="true" />
      <tradingAccount sdata:url="http://bharanidesktop:5495/sdata/accounts50/GCRM/{3C67D9B3-A00F-4F0A-A37C-F6B60E6306B5}/tradingAccountCustomer(efdb015d-7b05-4e61-898d-a62fe773b5fd)?format=atomentry" sdata:uuid="efdb015d-7b05-4e61-898d-a62fe773b5fd">
        <active>true</active>
        <customerSupplierFlag>Customer</customerSupplierFlag>
        <companyPersonFlag>Company</companyPersonFlag>
        <invoiceTradingAccount xsi:nil="true" />
        <openedDate xsi:nil="true" />
        <reference>ZEBRA</reference>
        <reference2 xsi:nil="true" />
        <status>Open</status>
        <name>Zebra</name>
        <shortName xsi:nil="true" />
        <type>Unknown</type>
        <registeredAddress xsi:nil="true" />
        <postalAddresses xsi:nil="true" />
        <shippingAddresses xsi:nil="true" />
        <billingAddresses xsi:nil="true" />
        <phones xsi:nil="true" />
        <emails xsi:nil="true" />
        <website />
        <contacts xsi:nil="true" />
        <deliveryContact xsi:nil="true" />
        <salesPersons xsi:nil="true" />
        <deliveryMethod xsi:nil="true" />
        <deliveryRule>true</deliveryRule>
        <currency>EUR</currency>
        <taxCode xsi:nil="true" />
        <taxReference />
        <taxationCountry>IE</taxationCountry>
        <useTaxInclusivePrices xsi:nil="true" />
        <financeBalance>0.00</financeBalance>
        <financeLimit>5000.00</financeLimit>
        <financeBalanceDate xsi:nil="true" />
        <financeStatusFlag>false</financeStatusFlag>
        <financeStatusText>Open</financeStatusText>
        <settlementDiscountType>Percent</settlementDiscountType>
        <settlementDiscountAmount xsi:nil="true" />
        <settlementDiscountPercent>0.00</settlementDiscountPercent>
        <settlementDiscountTerms>0</settlementDiscountTerms>
        <settlementDiscountTermsCommencement xsi:nil="true" />
        <settlementDiscountIncludedInTotal>true</settlementDiscountIncludedInTotal>
        <paymentTerms>0</paymentTerms>
        <paymentTermsCommencement xsi:nil="true" />
        <orderDiscountType xsi:nil="true" />
        <orderDiscountAmount xsi:nil="true" />
        <orderDiscountPercent xsi:nil="true" />
        <orderText1 xsi:nil="true" />
        <orderText2 xsi:nil="true" />
        <orderLineDiscountType xsi:nil="true" />
        <orderLineDiscountAmount xsi:nil="true" />
        <orderLineDiscountPercent>0.00</orderLineDiscountPercent>
        <orderLineText1 xsi:nil="true" />
        <orderLineText2 xsi:nil="true" />
        <invoiceDiscountType xsi:nil="true" />
        <invoiceDiscountAmount xsi:nil="true" />
        <invoiceDiscountPercent>0.00</invoiceDiscountPercent>
        <invoiceText1 xsi:nil="true" />
        <invoiceText2 xsi:nil="true" />
        <bankAccounts xsi:nil="true" />
        <tenderType xsi:nil="true" />
        <defaultFulfillmentLocation xsi:nil="true" />
        <pricelists xsi:nil="true" />
        <pricingOverride xsi:nil="true" />
        <accountingType xsi:nil="true" />
        <financialAccounts xsi:nil="true" />
        <primacyIndicator>true</primacyIndicator>
        <opportunities xsi:nil="true" />
        <salesQuotations xsi:nil="true" />
        <salesOrders xsi:nil="true" />
        <salesOrderDeliveries xsi:nil="true" />
        <salesInvoices xsi:nil="true" />
        <salesCredits xsi:nil="true" />
        <purchaseOrders xsi:nil="true" />
        <purchaseOrderDeliveries xsi:nil="true" />
        <receipts xsi:nil="true" />
        <interactions xsi:nil="true" />
        <projects xsi:nil="true" />
      </tradingAccount>
      <customerReference xsi:nil="true" />
      <opportunity xsi:nil="true" />
      <pricelist xsi:nil="true" />
      <copyFlag xsi:nil="true" />
      <date xsi:nil="true" />
      <time xsi:nil="true" />
      <taxDate xsi:nil="true" />
      <taxCodes>
        <taxCode sdata:uuid="0b694565-e5c8-490a-9c5a-a32571173d91">
          <notes xsi:nil="true" />
        </taxCode>
      </taxCodes>
      <postalAddresses xsi:nil="true" />
      <deliveryMethod xsi:nil="true" />
      <deliveryTerms xsi:nil="true" />
      <deliveryRule xsi:nil="true" />
      <deliveryDate xsi:nil="true" />
      <carrierCompany xsi:nil="true" />
      <carrierTradingAccount xsi:nil="true" />
      <carrierNetPrice>80.00</carrierNetPrice>
      <carrierTaxPrice>20.00</carrierTaxPrice>
      <carrierTotalPrice>100.00</carrierTotalPrice>
      <carrierSalesInvoice xsi:nil="true" />
      <carrierTaxCodes xsi:nil="true" />
      <carrierReference xsi:nil="true" />
      <currency xsi:nil="true" />
      <operatingCompanyCurrency xsi:nil="true" />
      <operatingCompanyCurrencyExchangeRate xsi:nil="true" />
      <operatingCompanyCurrencyExchangeRateOperator xsi:nil="true" />
      <operatingCompanyCurrencyExchangeRateDate xsi:nil="true" />
      <customerTradingAccountCurrency xsi:nil="true" />
      <customerTradingAccountCurrencyExchangeRate xsi:nil="true" />
      <customerTradingAccountCurrencyExchangeRateOperator xsi:nil="true" />
      <customerTradingAccountCurrencyExchangeRateDate xsi:nil="true" />
      <buyerContact xsi:nil="true" />
      <salespersons xsi:nil="true" />
      <salesInvoiceLines>
        <salesInvoiceLine sdata:uuid="00000000-0000-0000-0000-000000000000">
          <originatorDocumentLine xsi:nil="true" />
          <active xsi:nil="true" />
          <reference xsi:nil="true" />
          <reference2 xsi:nil="true" />
          <status xsi:nil="true" />
          <type>Standard</type>
          <number xsi:nil="true" />
          <commodity sdata:uuid="2e4f0611-0c32-4f25-8374-c814b90193d0">
            <commodityGroup xsi:nil="true" />
            <commodityIdentifiers xsi:nil="true" />
            <unitOfMeasure xsi:nil="true" />
            <buyingUnitOfMeasure xsi:nil="true" />
            <sellingUnitOfMeasure xsi:nil="true" />
            <packingUnitOfMeasure xsi:nil="true" />
            <supplierTradingAccount xsi:nil="true" />
            <taxCodes xsi:nil="true" />
            <financialAccounts xsi:nil="true" />
            <replacement xsi:nil="true" />
            <associatedChildCommodities xsi:nil="true" />
            <associatedParentCommodity xsi:nil="true" />
            <interactions xsi:nil="true" />
            <opportunities xsi:nil="true" />
            <salesQuotationLines xsi:nil="true" />
            <salesOrderLines xsi:nil="true" />
            <salesOrderDeliveryLines xsi:nil="true" />
            <salesInvoiceLines xsi:nil="true" />
            <salesCreditLines xsi:nil="true" />
            <purchaseOrderLines xsi:nil="true" />
            <purchaseOrderDeliveryLines xsi:nil="true" />
            <pricelists xsi:nil="true" />
            <prices xsi:nil="true" />
          </commodity>
          <text xsi:nil="true" />
          <deliveryTerms xsi:nil="true" />
          <deliveryDate xsi:nil="true" />
          <carrierTradingAccount xsi:nil="true" />
          <carrierNetPrice xsi:nil="true" />
          <carrierTaxPrice xsi:nil="true" />
          <carrierTotalPrice xsi:nil="true" />
          <carrierSalesInvoiceLine xsi:nil="true" />
          <carrierTaxCodes xsi:nil="true" />
          <carrierReference xsi:nil="true" />
          <unitOfMeasure xsi:nil="true" />
          <quantity>2.00</quantity>
          <initialPrice xsi:nil="true" />
          <pricelist xsi:nil="true" />
          <settlementDiscountType xsi:nil="true" />
          <settlementDiscountAmount xsi:nil="true" />
          <settlementDiscountPercent xsi:nil="true" />
          <settlementDiscountTerms xsi:nil="true" />
          <invoiceLineDiscountType xsi:nil="true" />
          <invoiceLineDiscountAmount xsi:nil="true" />
          <invoiceLineDiscountPercent xsi:nil="true" />
          <invoiceLineSubtotalDiscountType xsi:nil="true" />
          <invoiceLineSubtotalDiscountAmount xsi:nil="true" />
          <invoiceLineSubtotalDiscountPercent xsi:nil="true" />
          <actualPrice xsi:nil="true" />
          <netTotal>50.00</netTotal>
          <chargesTotal xsi:nil="true" />
          <discountTotal xsi:nil="true" />
          <fOBPoint xsi:nil="true" />
          <taxCodes>
            <taxCode sdata:uuid="0b694565-e5c8-490a-9c5a-a32571173d91">
              <notes xsi:nil="true" />
            </taxCode>
          </taxCodes>
          <priceTax xsi:nil="true" />
          <taxTotal>10.00</taxTotal>
          <grossTotal>60.00</grossTotal>
          <costTotal xsi:nil="true" />
          <profitTotal xsi:nil="true" />
          <project xsi:nil="true" />
          <salesOrderDeliveryLines xsi:nil="true" />
          <receipts xsi:nil="true" />
          <financialAccounts xsi:nil="true" />
          <notes xsi:nil="true" />
        </salesInvoiceLine>
      </salesInvoiceLines>
      <lineCount xsi:nil="true" />
      <originatorDocument xsi:nil="true" />
      <salesOrderDeliveries xsi:nil="true" />
      <receipts xsi:nil="true" />
      <contract xsi:nil="true" />
      <settlementDiscountType xsi:nil="true" />
      <settlementDiscountAmount xsi:nil="true" />
      <settlementDiscountPercent xsi:nil="true" />
      <settlementDiscountTerms xsi:nil="true" />
      <settlementDiscountIncludedInTotal xsi:nil="true" />
      <invoiceDiscountType xsi:nil="true" />
      <invoiceDiscountAmount xsi:nil="true" />
      <invoiceDiscountPercent xsi:nil="true" />
      <invoiceAdditionalDiscount1Type xsi:nil="true" />
      <invoiceAdditionalDiscount1Amount xsi:nil="true" />
      <invoiceAdditionalDiscount1Percent xsi:nil="true" />
      <invoiceAdditionalDiscount2 xsi:nil="true" />
      <invoiceAdditionalDiscount2Amount xsi:nil="true" />
      <invoiceAdditionalDiscount2Percent xsi:nil="true" />
      <netTotal xsi:nil="true" />
      <discountTotal xsi:nil="true" />
      <chargesTotal xsi:nil="true" />
      <taxTotal xsi:nil="true" />
      <grossTotal xsi:nil="true" />
      <costTotal xsi:nil="true" />
      <profitTotal xsi:nil="true" />
      <text1 xsi:nil="true" />
      <text2 xsi:nil="true" />
      <projects xsi:nil="true" />
      <financialAccounts xsi:nil="true" />
      <interactions xsi:nil="true" />
      <user xsi:nil="true" />
      <notes xsi:nil="true" />
      <CustomerId>0001-01-01T00:00:00.000+00:00</CustomerId>
      <paymentDue xsi:nil="true" />
    </salesInvoice>
  </sdata:payload>
</entry>
mbharanidharan88 commented 5 years ago

I figured out the issue, It was an authentication problem. The provided password was wrong but still, it will be better if it throws the correct exception. Thank you.

darroncockram commented 5 years ago

Strange. If I use the wrong password I get the expected 401 Unauthorised response.

darroncockram commented 5 years ago

Scratch that. I see what you mean. It's not an error for the server but from the client side deserialiser.

mbharanidharan88 commented 5 years ago

Scratch that. I see what you mean. It's not an error for the server but from the client side deserialiser.

Maybe you're right. However, the issue is resolved now. Thank you.