web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Not getting value inserted and upadated in tables

(0) ShareShare
ReportReport
Posted on by 1,836

I have created table " SalesOrderExim" and "SalesOrderEximLines"  , I am trying to insert and update  records in this tables but but not able to get this done 

can anybody suggest what is wrong with my code so i can get this in process. my code is below.

for salestable Extension,

[ExtensionOf(tableStr(SalesTable))]

final  class EximSalesTable_Extension
{
   

 public  void insert(boolean _skipMarkup )
    {

        SalesOrderExim                       salesOrderExim;
        SalesOrderEximLines                  salesOrderEximLines;
        CustInvoiceJour                      custInvoiceJour;
        SalesLine                            salesline;
        TaxInformationLegalEntity_IN         taxInformationLegalEntity_IN;
        TaxInformation_IN                    taxInformation_IN;
        str                                   IECNUMBER;

        next insert(_skipMarkup);

        select * from salesOrderExim
            where salesOrderExim.RefrenceRecId == this.RecId;

        select PANNumber from taxInformationLegalEntity_IN
            where taxInformationLegalEntity_IN.LegalEntity == companyInfo::find().RecId;

        taxInformation_IN   = TaxInformation_IN::findDefaultbyLocation(LogisticsPostalAddress::findByLocation(companyInfo::find().PrimaryAddressLocation).Location);

          IECNUMBER = TaxRegistrationNumbers_IN::find(taxInformation_IN.IECRegistrationNumberTable).RegistrationNumber;
          
        if(salesOrderExim.RefrenceRecId == this.RecId)
        {
            ttsbegin;
            salesOrderExim.Buyer                  = this.SalesName;
            salesOrderExim.Exporter               = companyinfo::find().Name;
            salesOrderExim.PANNumber              = taxInformationLegalEntity_IN.PANNumber;
            salesOrderExim.IECNumber              = IECNUMBER;
            salesOrderExim.State                  = companyInfo::find().postalAddress().State;
            salesOrderExim.Payment                =  this.Payment;
            salesOrderExim.TermsOfDelivery        =  this.DlvTerm;
            salesOrderExim.InvoiceId              = "";
            salesOrderExim.FromDate               = dateNull();
            salesOrderExim.insert();
            ttscommit;
        }      

    }

    public void update()     
    {
        SalesOrderExim                       salesOrderExim;
        SalesOrderEximLines                  salesOrderEximLines;
        CustInvoiceJour                      custInvoiceJour;
        SalesLine                            salesline;
        SalesTable                           salestable;
        TaxInformationLegalEntity_IN         taxInformationLegalEntity_IN;
        TaxInformation_IN                    taxInformation_IN;
        str                                   IECNUMBER;  
         
        next update();

        select PANNumber from taxInformationLegalEntity_IN
            where taxInformationLegalEntity_IN.LegalEntity == companyInfo::find().RecId;

        taxInformation_IN   = TaxInformation_IN::findDefaultbyLocation(LogisticsPostalAddress::findByLocation(companyInfo::find().PrimaryAddressLocation).Location);

        IECNUMBER = TaxRegistrationNumbers_IN::find(taxInformation_IN.IECRegistrationNumberTable).RegistrationNumber;

        salesId = this.SalesId;

        select * from  salestable
            where  salesTable.SalesId == salesId;

        select forupdate  salesOrderExim
            where   salesOrderExim.RefrenceRecId == this.RecId;
               
   
        if(this.SalesStatus==SalesStatus::Invoiced && salesOrderExim.InvoiceId == "")
        {
            select InvoiceId,InvoiceDate  from custInvoiceJour
                where custInvoiceJour.SalesId == this.SalesId;

            ttsbegin;
            salesOrderExim.InvoiceId              = custInvoiceJour.InvoiceId;
            salesOrderExim.FromDate               = custInvoiceJour.InvoiceDate;
            salesOrderExim.Buyer                  = this.SalesName;
            salesOrderExim.Exporter               = companyinfo::find().Name;
            salesOrderExim.PANNumber              = taxInformationLegalEntity_IN.PANNumber;
            salesOrderExim.IECNumber              = IECNUMBER;
            salesOrderExim.State                  = companyInfo::find().postalAddress().State;
            salesOrderExim.Payment                =  this.Payment;
            salesOrderExim.TermsOfDelivery        =  this.DlvTerm;
            salesOrderExim.update();
            ttscommit;
        }
                    
    }
}    
 

for salesline Extension

[ExtensionOf(tableStr(SalesLine))]

final class EximSalesLine_Extension
{

    public void  insert(boolean            _dropInvent ,
                        boolean            _findMarkup ,
                        Common             _childBuffer,
                        boolean            _skipCreditLimitCheck ,
                        boolean            _skipWHSProcesses ,
                        InventRefTransId   _interCompanyInventTransId ) 
    {

        SalesOrderEximLines    salesOrderEximLines;
        SalesTable             salesTable;
        SalesId                salesId;

        next insert();
          
        salesId = this.SalesId;

        select * from  salestable
            where  salesTable.SalesId == salesId;

        select * from  salesOrderEximLines
                join this
            where  salesOrderEximLines.RefRecId == this.RecId;

            if(salesOrderEximLines.HSNCode == "" )
            {
                ttsbegin;
                salesOrderEximLines.HSNCode  =   HSNCodeTable_IN::find(InventTable::find(this.ItemId).HSNCodeTable_IN).Code;
                salesOrderEximLines.insert();
                ttscommit;
            }
            
    }

    public void  update(boolean  _dropInvent  ,
                        Common   _childBuffer ,
                        boolean  _updateOrderLineOfDeliverySchedule ,
                        boolean  _mcrAutoallocate ,
                        boolean  _cameFromCreate ,
                        boolean  _promptSuppItem 
                        )

    {

        SalesOrderEximLines    salesOrderEximLines;
        SalesTable             salesTable;
        SalesId                salesId;
       
        next update();

        salesId = this.SalesId;

        select * from  salestable
            where  salesTable.SalesId == salesId;

        select * from  salesOrderEximLines
                join this
            where  salesOrderEximLines.RefRecId == this.RecId;

            if(salesOrderEximLines.HSNCode == "" )
            {
                ttsbegin;
                salesOrderEximLines.HSNCode  =   HSNCodeTable_IN::find(InventTable::find(this.ItemId).HSNCodeTable_IN).Code;
                salesOrderEximLines.insert();
               ttscommit;
            }
      
    }
}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,658 Most Valuable Professional on at
    RE: Not getting value inserted and upadated in tables

    Please explain your problem.

    "not able to get this done" doesn't say us whether you got an error and where or what else happened.

    Don't forget that the debugger can help if you have no idea about what's going on.

  • Dineshkarlekar Profile Picture
    1,836 on at
    RE: Not getting value inserted and upadated in tables

    when I  add new line in salesorder  my insert code for sales line show this error ,

    seems like i am not able to pass the refrence of my sales id  , debugger is showing different Recid for "salestable"  and "salesorderEximLines"

    which are not seemes as per relation , can you plz help me out .

    pastedimage1673853687366v1.png

    thanks,

    regards Dinesh.

  • Martin Dráb Profile Picture
    237,658 Most Valuable Professional on at
    RE: Not getting value inserted and upadated in tables

    Use the debugger to find out which line of code threw the error.

    That salesTable.RecId isnt the same as salesorderEximLines.RecId are different sounds completely correct to me. What would you expect them to be the same. If I understand your data model correctly, SalesOrderEximLines.RefRecId (not RecId) should contain RecId of SalesLine (not SalesTable).

  • Dineshkarlekar Profile Picture
    1,836 on at
    RE: Not getting value inserted and upadated in tables

    yes if i insert new line in salesline, the salesline.Recid Should pass into SalesOrderEximLines.REFrecId , i am not getting the salesline.Recid in debugger,

    when ever i create record in salesline in the RefRecId should get created in   SalesOrderEximLines.REFrecId but in my case its not happening the debugger is showing Salesline.RecId = 0 

  • Martin Dráb Profile Picture
    237,658 Most Valuable Professional on at
    RE: Not getting value inserted and upadated in tables

    Let's focus just on code relevant to this particular problem - what happens when you insert a record to SalesLine:

    [ExtensionOf(tableStr(SalesLine))]
    final class EximSalesLine_Extension
    {
    
        public void  insert(boolean            _dropInvent ,
                            boolean            _findMarkup ,
                            Common             _childBuffer,
                            boolean            _skipCreditLimitCheck ,
                            boolean            _skipWHSProcesses ,
                            InventRefTransId   _interCompanyInventTransId ) 
        {
            next insert();
              
    		SalesTable salesTable;
    
            select from salesTable
                where  salesTable.SalesId == this.SalesId;
    
    		SalesOrderEximLines salesOrderEximLines;
    
            select salesOrderEximLines
    			join this
                where salesOrderEximLines.RefRecId == this.RecId;
    
    		if (salesOrderEximLines.HSNCode == '')
    		{
    			ttsbegin;
    			salesOrderEximLines.HSNCode = HSNCodeTable_IN::find(InventTable::find(this.ItemId).HSNCodeTable_IN).Code;
    			salesOrderEximLines.insert();
    			ttscommit;
    		}
        }
    }

    You say that Salesline.RecId is zero, but there is no salesLine varaible in your code. Doesn't it mean that you're looking at a wrong place?

    You said you wanted to get RecId of SalesLine set to RefRecId of SalesOrderEximLines, but you don't have code for doing it.

    The statement 'join this' makes no sense - throw it away.

    Is there any reason for checking if SalesOrderEximLines already exists? How could it happen? I can't imagine that.

    Your code will try to create an addition record in SalesOrderEximLines if a record was found but HSNCode isn't populated. Isn't it a bug? Are you sure that having multiple SalesOrderEximLines for a single SalesLine is what you want? If so, you'll need to change other parts of your code.

    You select salesTable, but than you don't use it for anything. It's either meaningless and it should be removed, or it implies that you forgot to add some logic that needs SalesTable.

    I think you should call salesOrderEximLines.insert() in a transaction with the insertion of SalesLine.

    Let me suggest this solution:

    [ExtensionOf(tableStr(SalesLine))]
    final class EximSalesLine_Extension
    {
    
        public void  insert(boolean            _dropInvent ,
                            boolean            _findMarkup ,
                            Common             _childBuffer,
                            boolean            _skipCreditLimitCheck ,
                            boolean            _skipWHSProcesses ,
                            InventRefTransId   _interCompanyInventTransId ) 
        {
    		ttsbegin;
    	
            next insert();
              
    		SalesOrderEximLines salesOrderEximLines;
    		salesOrderEximLines.initValue();
    		salesOrderEximLines.RefRecId = this.RecId;
    		salesOrderEximLines.HSNCode = HSNCodeTable_IN::find(this.inventTable().HSNCodeTable_IN).Code;
    		if (!salesOrderEximLines.validateWrite())
    		{
    			// throw error
    		}
    		salesOrderEximLines.insert();
    		
    		ttscommit;
        }
    }

  • Dineshkarlekar Profile Picture
    1,836 on at
    RE: Not getting value inserted and upadated in tables

    Yes you are right I am facing the problem with additional record , when I insert new record in  table "salesOrderExim" after salesorder getting invoiced additional record for that sales order is generated in  "salesOrderExim" I do not want any additional record  in both table "salesOrderExim"  && "salesOrderEximLines"  

    DO I HAVE TO MAKE CHANGES in salestable extrension  code to avoid additional record .

    thanks 

    regards dinesh

  • Martin Dráb Profile Picture
    237,658 Most Valuable Professional on at
    RE: Not getting value inserted and upadated in tables

    Yes, of course you need to change your code to fix the bug.

  • Dineshkarlekar Profile Picture
    1,836 on at
    RE: Not getting value inserted and upadated in tables

    I have edited the code for both table , will it prevent to create additional record in table

    for salestable extensions

    [ExtensionOf(tableStr(SalesTable))]
    
    final  class EximSalesTable_Extension
    {
       
    
     public  void insert(boolean _skipMarkup )
        {
    
            SalesOrderExim                       salesOrderExim;
            SalesOrderEximLines                  salesOrderEximLines;
            CustInvoiceJour                      custInvoiceJour;
            SalesLine                            salesline;
            TaxInformationLegalEntity_IN         taxInformationLegalEntity_IN;
            TaxInformation_IN                    taxInformation_IN;
            str                                   IECNUMBER;
    
     ttsbegin;
            next insert(_skipMarkup);
    
            select * from salesOrderExim
                where salesOrderExim.RefrenceRecId == this.RecId;
    
            select PANNumber from taxInformationLegalEntity_IN
                where taxInformationLegalEntity_IN.LegalEntity == companyInfo::find().RecId;
    
            taxInformation_IN   = TaxInformation_IN::findDefaultbyLocation(LogisticsPostalAddress::findByLocation(companyInfo::find().PrimaryAddressLocation).Location);
    
              IECNUMBER = TaxRegistrationNumbers_IN::find(taxInformation_IN.IECRegistrationNumberTable).RegistrationNumber;
              
            if(salesOrderExim.RefrenceRecId == this.RecId)
            {
               
                salesOrderExim.Buyer                  = this.SalesName;
                salesOrderExim.Exporter               = companyinfo::find().Name;
                salesOrderExim.PANNumber              = taxInformationLegalEntity_IN.PANNumber;
                salesOrderExim.IECNumber              = IECNUMBER;
                salesOrderExim.State                  = companyInfo::find().postalAddress().State;
                salesOrderExim.Payment                =  this.Payment;
                salesOrderExim.TermsOfDelivery        =  this.DlvTerm;
                salesOrderExim.InvoiceId              = "";
                salesOrderExim.FromDate               = dateNull();
                salesOrderExim.insert();
               
            }  
            
             ttscommit;
    
        }
    
        public void update()     
        {
            SalesOrderExim                       salesOrderExim;
            SalesOrderEximLines                  salesOrderEximLines;
            CustInvoiceJour                      custInvoiceJour;
            SalesLine                            salesline;
            SalesTable                           salestable;
            TaxInformationLegalEntity_IN         taxInformationLegalEntity_IN;
            TaxInformation_IN                    taxInformation_IN;
            str                                   IECNUMBER;  
             
         ttsbegin;
            next update();
    
            select PANNumber from taxInformationLegalEntity_IN
                where taxInformationLegalEntity_IN.LegalEntity == companyInfo::find().RecId;
    
            taxInformation_IN   = TaxInformation_IN::findDefaultbyLocation(LogisticsPostalAddress::findByLocation(companyInfo::find().PrimaryAddressLocation).Location);
    
            IECNUMBER = TaxRegistrationNumbers_IN::find(taxInformation_IN.IECRegistrationNumberTable).RegistrationNumber;
    
            select forupdate  salesOrderExim
                where   salesOrderExim.RefrenceRecId == this.RecId;
                   
            if(this.SalesStatus==SalesStatus::Invoiced)
            {
                select InvoiceId,InvoiceDate  from custInvoiceJour
                    where custInvoiceJour.SalesId == this.SalesId;
    
               
                salesOrderExim.InvoiceId              = custInvoiceJour.InvoiceId;
                salesOrderExim.FromDate               = custInvoiceJour.InvoiceDate; 
                salesOrderExim.update();
               
            }
             
         ttscommit;           
        }
    }    

    for salesline extension

    [ExtensionOf(tableStr(SalesLine))]
    
    final class EximSalesLine_Extension
    {
    
        public void  insert(boolean            _dropInvent ,
                            boolean            _findMarkup ,
                            Common             _childBuffer,
                            boolean            _skipCreditLimitCheck ,
                            boolean            _skipWHSProcesses ,
                            InventRefTransId   _interCompanyInventTransId ) 
        {
            ttsbegin;
     
            next insert();
              
            SalesOrderEximLines salesOrderEximLines;
            salesOrderEximLines.initValue();
            salesOrderEximLines.RefRecId = this.RecId;
            salesOrderEximLines.HSNCode = HSNCodeTable_IN::find(this.inventTable().HSNCodeTable_IN).Code;
            if (!salesOrderEximLines.validateWrite())
            {
                error("Parameter value is invalid");
            }
            salesOrderEximLines.insert();
      
            ttscommit;
                      
        }
    }

    thanks,

    Regards , Dinesh

  • Martin Dráb Profile Picture
    237,658 Most Valuable Professional on at
    RE: Not getting value inserted and upadated in tables

    As I mentioned in your previous thread, an order may be used in several invoices. Your code doesn't take it into account. Also, it's not true that when there is an invoice, the status of the order must be Invoiced. It's not true for partial invoices.

    Another problem is in error("Parameter value is invalid"). You miss the 'throw' keyword, therefore no exception will get thrown. If invalid data is being inserted, you put a message to infolog but you insert the invalid record anyway.

  • Dineshkarlekar Profile Picture
    1,836 on at
    RE: Not getting value inserted and upadated in tables

    hi , Martin 

    I have made changes in code as you suggessted , but when i debug my code ie when i add new line the in sales line the debugger jumps on the update() method of salestable then it checks the condition and it jumps on the insert method of salesline then it throw error on next insert  of sales line extension, do i have to make changes in update() of sales table or in insert() method of salesline.

    pastedimage1673867260638v1.png 

     

    ExtensionOf(tableStr(SalesLine))]
    
    final class EximSalesLine_Extension
    {
    
        public void  insert(boolean            _dropInvent ,
                            boolean            _findMarkup ,
                            Common             _childBuffer,
                            boolean            _skipCreditLimitCheck ,
                            boolean            _skipWHSProcesses ,
                            InventRefTransId   _interCompanyInventTransId ) 
        {
            ttsbegin;
     
            next insert();
              
            SalesOrderEximLines salesOrderEximLines;
            salesOrderEximLines.initValue();
            salesOrderEximLines.RefRecId = this.RecId;
            salesOrderEximLines.HSNCode = HSNCodeTable_IN::find(this.inventTable().HSNCodeTable_IN).Code;
            if (!salesOrderEximLines.validateWrite())
            {
               throw error("Parameter value is invalid");
            }
            salesOrderEximLines.insert();
      
            ttscommit;
                      
        }
    }    
     

    thanks ,

    Regards,Dinesh

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 776 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 606 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 402 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans