Skip to main content

Notifications

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

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!

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

    thanks Mohit & Girish,

    Now Its's working fine

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,552 Super User 2024 Season 1 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.

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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
    Mohit Rampal 12,552 Super User 2024 Season 1 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);

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

    Okay Girish

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n 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
    GirishS 27,821 Super User 2024 Season 1 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
    @rp@n on at
    RE: PurchLine.delete called incorrectly message popup when trying to delete record form purchLine

    Exactly on the next delete()

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 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.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,965 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,836 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans