Announcements
No record found.
I just shifted the code to another version and I got this error while debugging
After debugging, I got this error
Hi ,
The error states there is some issue in line 684 in the class 'SalesInvoiceController' .
Have you added any custom code in the extension?
No
In your first pic, the code looks like a custom one.
Can you explain where this code is and what process calls this code?
Yes that code was custom. And that code is related to my custom class.
I want to run SO that process is calling this code.
You know the problem - there is an (invalid) attempt to put PurchPurchaseOrderContract instance to a variable of SalesInvoiceContract type.
And you know where exactly it happens - in SalesInvoiceController.preRunModifyContract(), as line 684. It's obvious that PurchPurchaseOrderContract shouldn't be used there, therefore it seems that you've somehow put a wrong constract there.
Unfortunately your last screenshot doesn't show any code (just the method declaration), therefore we can't comment on it. But what I said should give you an idea about where to look for the bug.
I did just customization on my custom form and did not use PurchPurchaseOrderContract, SalesInvoiceContract, SalesInvoiceController.preRunModifyContract().
Got an error(Unable to cast object of type 'Dynamics.AX.Application.PurchPurchaseOrderContract' to type 'Dynamics.AX.Application.SalesInvoiceContract') on this line of code while debugging
salesFormLetter.update(salesTable,DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()),SalesUpdate::All,AccountOrder::None,noYes::No,noYes::Yes);
No, this isn't the line where the error is thrown. It's thrown at SalesInvoiceController.preRunModifyContract(), as discussed above.
It might suggests that you don't know how to debug standard code. Is it the case?
You see that you're unable to identify the cause if you don't go deeper with your debugging.
Thanks a lot Martin, when I went deeper with my debugging I got the actual cause.
I got the actual cause, someone set the custom purchase order report in sales module.
Here is the code for new setup.
class PrintMgtDocTypeHandlersExt
{
[SubscribesTo(classstr(PrintMgmtDocType), delegatestr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
public static void getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
_result.result(ssrsReportStr(SalesInvoice, Report));
}
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.
Congratulations to our 2026 Super Stars!
Thanks to all of our 2025 Community Spotlight stars!
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Giorgio Bonacorsi 617
André Arnaud de Cal... 461 Super User 2026 Season 1
Syed Haris Shah 298 Super User 2026 Season 1