Skip to main content

Notifications

Announcements

No record found.

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

  • Suggested answer
    Don Shields Profile Picture
    Don Shields 650 on at
    RE: SalesParmLine event handlers not working

    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.

  • Giridhar1617 Profile Picture
    Giridhar1617 on at
    RE: SalesParmLine event handlers not working

    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

  • Verified answer
    Don Shields Profile Picture
    Don Shields 650 on at
    RE: SalesParmLine event handlers not working

    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

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: SalesParmLine event handlers not working

    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.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,661 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,379 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans