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, ...
Answered

PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

(0) ShareShare
ReportReport
Posted on by 30

Hi All,

When I create a new record in Purchline then in my custom table,  also record got inserted. And it is working fine.

Suppose , I delete any line from PurchLine then i like to delete the same record from my custom table.

I have a parameter, based on the parameter the record got inserted in my custom table. In the similar way, I try to  delete the record from my custom table

For this, I wrote below  code in Delete method on PurchLine extension class

public void delete(boolean _showInfoDelReserv , boolean updateOrderLineOfDeliverySchedule)
    {
        PurchQtyTracking      purchQtyTracking,purchQtyTrackingDelete;
        RefRecId              recId;
        PurchParameters	      purchParameters;

        purchParameteres = PurchParameters::find();

        if (purchParameters.PurchLineQtyChecking == noyes::Yes)
        {

        select * from purchQtyTracking
            where purchQtyTracking.RefRecId == this.RecId;

        if (purchQtyTracking)
        {
            recId = purchQtyTracking.RefRecId;
        }        

        next delete();
        
        // if any record delete from purchline then the same record should  delete from PurchQtyTracking also
        if (recId != 0)
        {
            delete_from  purchQtyTrackingDelete
                where purchQtyTrackingDelete.RefRecId == recId;
        }
        }
     
    }

the requirement is -

If the parameter set to YES

if record exist in PurchQtyTracing table then it should DELETE the record from both tables - Purch Line & PurchQtyTracking

If record NOT exist in PurchQtyTracking table, then it should DELETE record forom PurchLine. only

But when I tried to delete record form PurchLine then I got message "PurchLine.delete method called incorrectly"

If parameter is set to NO

then it shuold called standard delete operation only 

Note - I not tried for delete action because the above delete operation execute based on parameter. 

In delete action we can't set parameter. And it will work globally. So, I go for code in PurchLine -  delete method

Pls give me more shed on this.

thansk!

I have the same question (0)
  • GirishS Profile Picture
    27,825 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Hi,

    Have you debugged the code written in the delete method. Exactly at what line the error is throwing?

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    30 on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Exactly on the next delete()

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Try the same logic on the delete event handler instead of COC.

    Thanks,

    Girish

  • @rp@n Profile Picture
    30 on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    sure Girish, let me check and will update you.

    CoC and Event handler - I know that how to call. Kindly let me know which one is recomanded to use ?

    I know Pre or Post event handler similar to next call before custom code and after custom cide.

    pls give me more shed on this.

    thanks!

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    You can use either of them. It depends on the situation and on the developer hands to go for event handler or COC.

    There are no recommendations to particularly use COC or event handler.

    Thanks,

    Girish S.

  • @rp@n Profile Picture
    30 on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Okay Girish

  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Hi, You are calling delete incorrectly, please add parameters same as standard method

    next delete(_showInfoDelReserv , updateOrderLineOfDeliverySchedule);

  • GirishS Profile Picture
    27,825 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    If it's an optional parameter, I think it's not compulsory to call that in the next keyword.

    I am not sure there. Please give it a try.

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,563 Moderator on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Also, Can you try moving next statement out of the if loop.

  • @rp@n Profile Picture
    30 on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    thanks Mohit & Girish,

    Now Its's working fine

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,100

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 633 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans