Get HSN Code using x++

 


Get the HSN Code for sales line using x++ in D365FO.


  
    TaxDocumentRowTransaction       taxDocumentRowTransaction;
    TaxDocumentRowTransaction_IN    taxDocumentRowTransaction_IN;
    SalesTable                      salesTable;
    SalesLine_IN                    salesLine_IN;
    SalesLine                       salesLine;
    CustInvoiceTrans                _custInvoiceTrans;

    select SalesLine where salesLine.salesId == 'SO-000125';

    _custInvoiceTrans   = CustInvoiceTrans::findInventTransid(salesLine.InventTransId);
    salesLine_IN        = _custInvoiceTrans.salesLine().salesLine_IN();

    Select RecId, TransactionJourLineRecId from taxDocumentRowTransaction
        where taxDocumentRowTransaction.TransactionJourLineRecId == _custInvoiceTrans.RecId
    join HSNCode, TaxDocumentRowTransactionRecId from taxDocumentRowTransaction_IN
        where taxDocumentRowTransaction_IN.TaxDocumentRowTransactionRecId == taxDocumentRowTransaction.RecId;

    if(taxDocumentRowTransaction_IN)
    {
        Info(strFmt('HSN- %1', taxDocumentRowTransaction_IN.HSNCode));

        /*select * from taxTrans where taxTrans.SourceRecId == custInvoiceTrans.RecId
            join taxTrans_IN where taxTrans_IN.RefRecId == taxTrans.RecId;
        if(taxTrans_IN)
        {
            // HSNCodeTable_IN::find(taxTrans_IN.HSNCodeTable).Code;
        }*/
    }
    else
    {
        Info(strFmt('HSN - %1', HSNCodeTable_IN::find(salesLine_IN.HSNCodeTable).Code));
    }

Comments