Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

SalesParmLine event handlers not working

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

  • 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.

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,339 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,177 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans