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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

SalesParmLine event handlers not working

(0) ShareShare
ReportReport
Posted on by 650

I'm trying to trigger some activity with a sales invoice by writing an onInserted() event handler for the SalesParmLine table.  My issue is that this is never triggered.  I have tried both of these methods.  Does anyone know why these wouldn't be fired?  Any alternative recommendations?  I can't use the SalesEditLines form event handlers because we will be using batch invoicing.

#1)

[PostHandlerFor(tableStr(SalesParmLine), tableMethodStr(SalesParmLine, insert))]

public static void SalesParmLine_Post_insert(XppPrePostArgs args)

{

SalesParmLine salesParmLineLoc;

Common tablefromevent;

CustPackingSlipJour custPackingSlipJourLoc;

SalesParmTable salesParmTableLoc;

SalesParmSubTable salesParmSubTableLoc;

SalesTable salesTableLoc;

;

//salesTableLoc = args.getThis();

tablefromevent = args.getThis();

if(tablefromevent.TableId==tableNum(SalesParmLine))

{

salesParmLineLoc = tablefromevent;

salesParmTableLoc = salesParmLineLoc.salesParmTable();

salesTableLoc = salesParmTableLoc.salesTable();

if(salesParmTableLoc.ParmJobStatus == ParmJobStatus::Waiting)

{

select firstonly salesParmSubTableLoc where salesParmSubTableLoc.ParmId == salesParmTableLoc.ParmId && salesParmSubTableLoc.TableRefId == salesParmTableLoc.TableRefId && salesParmSubTableLoc.journalRefTableId==tableNum(CustPackingSlipJour);

select firstonly custPackingSlipJourLoc where custPackingSlipJourLoc.RecId==salesParmSubTableLoc.JournalRefRecId;

//call caclulation //trigger tax code.

 //run custom code here.

}

}

}

#2)

[DataEventHandler(tableStr(SalesParmLine), DataEventType::Inserted)]

public static void SalesParmLine_onInserted(Common sender, DataEventArgs e)

{

SalesParmLine salesParmLineLoc;

Common tablefromevent;

CustPackingSlipJour custPackingSlipJourLoc;

SalesParmTable salesParmTableLoc;

SalesParmSubTable salesParmSubTableLoc;

SalesTable salesTableLoc;

;

tablefromevent = sender;

if(tablefromevent.TableId==tableNum(SalesParmLine))

{

salesParmLineLoc = tablefromevent;

salesParmTableLoc = salesParmLineLoc.salesParmTable();

salesTableLoc = salesParmTableLoc.salesTable();

if(salesParmTableLoc.ParmJobStatus == ParmJobStatus::Waiting)

{

select firstonly salesParmSubTableLoc where salesParmSubTableLoc.ParmId == salesParmTableLoc.ParmId && salesParmSubTableLoc.TableRefId == salesParmTableLoc.TableRefId && salesParmSubTableLoc.journalRefTableId==tableNum(CustPackingSlipJour);

select firstonly custPackingSlipJourLoc where custPackingSlipJourLoc.RecId==salesParmSubTableLoc.JournalRefRecId;

//call caclulation //trigger tax code.

 //run custom code here.

}

}

}

Thanks,

Don Shields

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi,

    In the first method you had putted this : tablefromevent = args.getThis();

    this is wrong the correct away is to put :  salesParmLineLoc = args.getThis();

    beacuse args.getThis() allow you to get instance of the object that you made the event handler in this context you made the event handler int the SalesParmLine table that's why this code don't work.

  • Verified answer
    Don Shields Profile Picture
    650 on at

    I had changed that however the event handler wasn't being called at all.  I found the root cause is that the SalesParmLines records get inserted via a RecordInsertList object (RecordInsertList.InsertDatabase()).  Apparently this by passes event handlers on the table methods. 

    Thanks for the input,

    Don

  • Giridhar1617 Profile Picture
    on at

    Hi Don,

    I am having the similar issue.. insertDatabase() by passes the event handlers.. I would like to know how did you trigger your logic in these situations..

    Thank you in advance..

    Regards,

    Giridhar

  • Suggested answer
    Don Shields Profile Picture
    650 on at

    I did a method extension on one of the controller classes instead.  FormLetterService.postsalesinvoice() I believe.  I don't have it in front of me right now but I debugged the invoice post until I found the proper method to override.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans