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; } } }
hi martin ,
thanks for helping me out,
finally i am able to insert & update values in my table without any additional record,
here is my code . i will also try to do this with child table
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; 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.RefrenceRecId = this.RecId; salesOrderExim.InvoiceId = ""; salesOrderExim.FromDate = dateNull(); salesOrderExim.insert(); ttscommit; } public void update() { SalesOrderExim salesOrderExim; CustInvoiceJour custInvoiceJour; ttsbegin; next update(); 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; } }
thanks,
regards ,Dinesh
All right, so you're saying that an exception gets thrown even before your code, therefore what code you have after next insert() is irrelevant. Do you agree?
I would start debugging from the place that throws the error, which - according to the stack trace you shared above - is InventMovement::constructNoThrow(). Debug it to see where it fails and which object references is null. Then investigate why.
Now i have put debugger , below are the screes
when i proceed further i get this
I think new recid is not falling into "SalesOrderEximLines"
Your screenshot doesn't show where you stopped the execution and at variables of which method you're looking at. Please at the information.
The Locals windows shows variables that - according to yourself - don't exist in EximSalesLine_Extension.insert(), therefore you're either looking at a wrong method or your code isn't compiled correctly.
I have keep debugger on insert and update of salestable extension , and on insert of salesline extension, so thats why it was jumping on salestable update()
i have removed it , now i have debugger only on insert of salesline and what i am getting is this. now the value of this. Recid = 0 so thats why SalesOrderEximLines.RefrenceRecid is taking first value from table which is not required , this. RecId must show the new line Recid which i have created.
Thanks,
Regards, Dinesh
Please elaborate what you mean by "after that it goes to". Either the exception is unhandled and it breaks the execution, or it goes to a catch clause. Execution can't magially jump to SalesTable.update().
I have no idea what you mean by "it check all the code of update statement don't know why , when this happens I don't get any value in this section of update". Just a guess - it might suggest that you don't execute your latest code. Rebuild the solution and try it again.
I have check stack trace properties, this is what it shows,
at Microsoft.Dynamics.Ax.Xpp.Common.get_CommonImplementation() at Microsoft.Dynamics.Ax.Xpp.Common.get_TableId() at Dynamics.AX.Application.InventMovement.`constructNoThrow(Common _buffer, InventMovSubType _subType, Common _childBuffer, Boolean @_subType_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet) in xppSource://Source/Foundation\AxClass_InventMovement.xpp:line 9012 at Dynamics.AX.Application.InventMovement.InventMovementCoCHelper.`constructNoThrow(InventMovement instance, Common arg0, InventMovSubType arg1, Common arg2, Boolean , Boolean ) at Dynamics.AX.Application.InventMovementWESBackoffice_Extension.constructNoThrow(Common _buffer, InventMovSubType _subType, Common _childBuffer) in xppSource://Source/WarehouseExecutionWorkloadBackoffice\AxClass_InventMovementWESBackoffice_Extension.xpp:line 17 at Dynamics.AX.Application.InventMovement.InventMovementCoCHelper.`constructNoThrow(InventMovement instance, Common arg0, InventMovSubType arg1, Common arg2, Boolean , Boolean ) at Dynamics.AX.Application.InventMovement.constructNoThrow(Common _buffer, InventMovSubType _subType, Common _childBuffer, Boolean @_subType_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet) at Dynamics.AX.Application.InventMovement.constructNoThrow(Common _buffer, InventMovSubType _subType, Common _childBuffer) at Dynamics.AX.Application.InventMovement.`construct(Common _buffer, InventMovSubType _subType, Common _childBuffer, Boolean @_subType_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet) in xppSource://Source/Foundation\AxClass_InventMovement.xpp:line 8959 at Dynamics.AX.Application.InventMovement.construct(Common _buffer, InventMovSubType _subType, Common _childBuffer, Boolean @_subType_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet) at Dynamics.AX.Application.InventMovement.construct(Common _buffer, InventMovSubType _subType, Common _childBuffer) at Dynamics.AX.Application.SalesLineType.`instantiateInventMovement(InventMovSubType _inventMovSubType, Common _childBuffer) in xppSource://Source/Foundation\AxClass_SalesLineType.xpp:line 1013 at Dynamics.AX.Application.SalesLineType.instantiateInventMovement(InventMovSubType _inventMovSubType, Common _childBuffer) at Dynamics.AX.Application.SalesLineType.`instantiateInventUpd_Estimated(Common _childBuffer, InventMovSubType _inventMovSubType) in xppSource://Source/Foundation\AxClass_SalesLineType.xpp:line 991 at Dynamics.AX.Application.SalesLineType.instantiateInventUpd_Estimated(Common _childBuffer, InventMovSubType _inventMovSubType) at Dynamics.AX.Application.SalesLineType.`updateInventoryOnInsert(Common _childBuffer) in xppSource://Source/Foundation\AxClass_SalesLineType.xpp:line 4754 at Dynamics.AX.Application.SalesLineType.updateInventoryOnInsert(Common _childBuffer) at Dynamics.AX.Application.SalesLine.`handleStockedItemsAndProject(SalesLineType _salesLineType, Boolean _dropInvent, Common _childBuffer) in xppSource://Source/Foundation\AxTable_SalesLine.xpp:line 16891 at Dynamics.AX.Application.SalesLine.handleStockedItemsAndProject(SalesLineType _salesLineType, Boolean _dropInvent, Common _childBuffer) at Dynamics.AX.Application.SalesLine.`insert(Boolean _dropInvent, Boolean _findMarkup, Common _childBuffer, Boolean _skipCreditLimitCheck, Boolean _skipWHSProcesses, String _interCompanyInventTransId, Boolean @_dropInvent_IsDefaultSet, Boolean @_findMarkup_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet, Boolean @_skipCreditLimitCheck_IsDefaultSet, Boolean @_skipWHSProcesses_IsDefaultSet, Boolean @_interCompanyInventTransId_IsDefaultSet) in xppSource://Source/Foundation\AxTable_SalesLine.xpp:line 4925 at Dynamics.AX.Application.SalesLine.SalesLineCoCHelper.`insert(SalesLine instance, Boolean arg0, Boolean arg1, Common arg2, Boolean arg3, Boolean arg4, String arg5, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean ) at Dynamics.AX.Application.EximSalesLine_Extension.insert(SalesLine this, Boolean _dropInvent, Boolean _findMarkup, Common _childBuffer, Boolean _skipCreditLimitCheck, Boolean _skipWHSProcesses, String _interCompanyInventTransId) in xppSource://Source/EXIMDevlopement\AxClass_EximSalesLine_Extension.xpp:line 15 at Dynamics.AX.Application.SalesLine.SalesLineCoCHelper.`insert(SalesLine instance, Boolean arg0, Boolean arg1, Common arg2, Boolean arg3, Boolean arg4, String arg5, Boolean , Boolean , Boolean , Boolean , Boolean , Boolean ) at Dynamics.AX.Application.SalesLine.insert(Boolean _dropInvent, Boolean _findMarkup, Common _childBuffer, Boolean _skipCreditLimitCheck, Boolean _skipWHSProcesses, String _interCompanyInventTransId, Boolean @_dropInvent_IsDefaultSet, Boolean @_findMarkup_IsDefaultSet, Boolean @_childBuffer_IsDefaultSet, Boolean @_skipCreditLimitCheck_IsDefaultSet, Boolean @_skipWHSProcesses_IsDefaultSet, Boolean @_interCompanyInventTransId_IsDefaultSet) at Dynamics.AX.Application.SalesLine.insert() at SalesLine::Insert(Object , Object[] , Boolean& ) at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeInstanceCall(Object instance, String MethodName, Object[] parameters)
dont know when i insert the line in line tab , first it goes to insert code of salesline where it check upto next insert ;
after that it goes to
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; }
it check all the code of update statement don't know why , when this happens I don't get any value in this section of update,
after checking this code debugger again jumps on salesline insert method then it throws the object refrence error on next insert ();
i hope you getting my problem,
select forupdate salesOrderExim where salesOrderExim.RefrenceRecId == this.RecId;
thanks ,
Regards, Dinesh
Please elaborate what you mean by "it checks the condition and it jumps on the insert method of salesline". Which line of code are you talking about. Why is it creating a new line on SalesTable update?
Also, check out which line of code inside inside insert() throws the exception. Start by clicling "View details" (in the dialog shown in your first screenshot) and and looking at the StackTrace property.
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.
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
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.
André Arnaud de Cal...
291,979
Super User 2025 Season 1
Martin Dráb
230,848
Most Valuable Professional
nmaenpaa
101,156