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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

How to Delete a PO Line without a PO Header

(0) ShareShare
ReportReport
Posted on by 8
I'm trying to delete an erroneous PO Line for which the PO Header has already been deleted. As shown in the attached screenshot, this PO Line (line 30) on PO #(Anonymized) populates in our purchase order lines database, but if we try to click into the PO Header name (PO#Anonymized), it shows no such PO. This PO Line will not be erased if I try alt+delete for the record. Essentially there should be no such PO Line, and it's impeding accuracy in our database (since there's a PO Line that should not be there). How can I delete this PO Line without a parent PO Header?
  • Leah Ju Profile Picture
    Microsoft Employee on at
    Hi Partner,
    Could you tell me what app you are using in Dynamics 365?
  • CU27040905-5 Profile Picture
    8 on at
    @Leah Ju, I am using Microsoft Dynamics 365 Finance/Operations.
  • Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at
    Moved from Dynamics 365 general forum.
     
    Which form are you talking about? Does it allow deletion at all? What happens when you try to delete the line?
     
    In general, it's quite often such corrupted data can't be fixed through GUI, because the application is designed to work with a consistent database. Therefore you may need a script to deal with it.
  • CU27040905-5 Profile Picture
    8 on at
    @Martin Dráb I'm in the "Procurement and Sourcing" Module within Purchase Orders, typically I'd be able to cancel the deliver remainder and it would effectively cancel the PO--however, I can only access that functionality when the Purchase Order is accessible from the PO Headers View.
  • Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at
    I don't understand how you can see that in the Purchase orders form. There you see lines for the selected header and if you have no header to select, how you can see its lines?
  • CU27040905-5 Profile Picture
    8 on at
    @Martin Dráb Sorry for not clarifying--this PO Line is visible within the "All PO Lines" form, which is inclusive of all lines across different headers. but if I try to click into the specific PO Header itself for that particular line, listed as the "parent" of this "stray" line, it shows no such header--just a blank field where the full PO Header view would normally be available.
     
    I agree with you that it doesn't make sense that a PO Line would remain an entry in our PO Lines without a parent header I can modify--this is not normally the case, which is why I posted this inquiry, because I have not had this issue before. The fact that this "phantom" PO Line exists within our PO Lines is impacting our summary data compiled via export, which is why I'm hoping to delete it.
     
    Do you have an example of a script I could use or a resource I could visit to learn how to draft a script which would navigate past the GUI and address this issue?
     
    Thank you kindly for the context you've already provided, I appreciate this info. 
  • Martin Dráb Profile Picture
    240,744 Most Valuable Professional on at
    I don't see All PO Lines form, but it's likely that it doesn't allow record deletion at all (it's the case of the Backorder purchase lines form, for instance). You didn't answer my question about the deletion, but I guess this is the cause.
     
    Deleting a record is, usually, very simple. Something like this:
    ttsbegin;
    
    PurchLine purchLine = PurchLine::findRecId(123456, true);
    purchLine.delete();
    
    ttscommit;
    But it's quite possible that it'll fail in this case if there is no header.
     
    You could delete the line directly by doUpdate() or in database, but I wouldn't do it without careful analysis. For example, there may be inventory transactions and if we deleted the order line and not them, we would just shift the data inconsistency somewhere else instead of fixing it.
  • André Arnaud de Calavon Profile Picture
    307,166 Super User 2026 Season 2 on at
    Hi,
     
    Can you tell us if your question has been solved in the meantime? If so, it would be great if you could mark answers that helped you. If not, feel free to update your question with your latest observations. We then might be able to help you.
  • Navneeth Nagrajan Profile Picture
    2,699 Super User 2026 Season 2 on at
    Hi,
     
    Martin's script is correct but it looks like there have been PO Headers that have been deleted forcefully or altered without the PO Lines being validated or deleted? This can happen if the PO is an Open Purchase order. Looks like a script has been fired from the database (In case of a non-production environment) to forcefully remove the Purchase order header.
     
    Happy to answer questions, if any.
     
     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 426 Most Valuable Professional

#2
CU10121822-0 Profile Picture

CU10121822-0 358

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 353 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans