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

Notifications

Announcements

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,829 Moderator on at

    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

    Exactly on the next delete()

  • GirishS Profile Picture
    27,829 Moderator on at

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

    Thanks,

    Girish

  • @rp@n Profile Picture
    30 on at

    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,829 Moderator on at

    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

    Okay Girish

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

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

    next delete(_showInfoDelReserv , updateOrderLineOfDeliverySchedule);

  • GirishS Profile Picture
    27,829 Moderator on at

    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,565 Moderator on at

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

  • @rp@n Profile Picture
    30 on at

    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…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
André Arnaud de Calavon Profile Picture

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

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 437 Super User 2025 Season 2

#3
Martin Dráb Profile Picture

Martin Dráb 348 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans