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

Unable to cast object of type 'Dynamics.AX.Application.SalesTable' to type 'System.String'.

(0) ShareShare
ReportReport
Posted on by

Hi all,

During creation custom Workflow for Sales, I hit error like when first open Sales Order (SalesTable form)

Unable to cast object of type 'Dynamics.AX.Application.SalesTable' to type 'System.String'.

If I debug, it hit at my CoC class for adding CanSubmitToWorfklow like this :

[ExtensionOf(tableStr(SalesTable))]
final class FMSalesTableCanSubmitToWorflow_Extension
{
    public boolean canSubmitToWorkflow(str _workflowtype)
    {
        boolean ret;

        ret = next canSubmitToWorkflow(_workflowtype);

        if(this.recID && this.WorkflowStatus == CFMJournalWorkflowStatus::NotSubmitted && this.existSalesLine())
        {
            ret = true;
        }
        return ret;
    }
}

The error hit at the end of "ret = next canSubmitToWorkflow(_workflowtype);"

Any idea what is that about ? 

  • Jeremy_Mounet Profile Picture
    170 on at

    Hi

    The canSubmitToWorkflow method seems to belong to the form and not to the salesTable Table.

    Your Chain of command references the table and not the form ([ExtensionOf(formstr(SalesTable))]).

    Jérémy.

  • Gunjan Bhattachayya Profile Picture
    35,429 on at

    Hi WOng,

    You are extending the form SalesTable. Right?

    Shouldn't the class read like this -

    [ExtensionOf(formStr(SalesTable))]
    final class FMSalesTableCanSubmitToWorflow_Extension

  • Community Member Profile Picture
    on at

    Hi,

    I'm sorry, is there a blog with complete solution for this custom workflow on standard table ?

    Since there are bunch of blog explain to extend the table instead. But most of them maybe outdated already.

    Microsoft docs also suggested the table :

    docs.microsoft.com/.../method-wrapping-coc

    Thanks,

  • Jeremy_Mounet Profile Picture
    170 on at

    For me your code could work like this :

    Add ret in your condition to add more cirteria.

    Change the FormStr of the extension attribute.

    Work on the data of the form ("this" keyword is not related to a table buffer on form).

    [ExtensionOf(FormStr(SalesTable))]
    final class FMSalesTableCanSubmitToWorflow_Extension
    {
        public boolean canSubmitToWorkflow(str _workflowtype)
        {
            boolean ret;
    
            ret = next canSubmitToWorkflow(_workflowtype);
    
            if(ret // put your condition here based on datasources of the form)
            {
                ret = true;
            }
            return ret;
        }
    }

  • Community Member Profile Picture
    on at

    Hi jeremy,

    I'm sorry, just added on my last reply, Actually Microsoft doc also suggested in table instead

    docs.microsoft.com/.../method-wrapping-coc

    For the code inside,  I think the same, only the matters is, is it on Table or Form ?

    thanks,

  • Verified answer
    Jeremy_Mounet Profile Picture
    170 on at

    Yes, Microsoft give an example of implementation based on Table for "extension", and the "canSubmitToWorkflow" method is often implemented in the target table (such as PurchTable).

    But in your case and for the Sales Orders workflow submission check, the method is developed on the form in the standard. If you would like to create an extension on, you should based your extension on the object where the method is implemented.

    I think this is why you are stuck.

    I let you try and update this thread about the verified status.

    Jérémy.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,099 on at

    Hi WWwong,

    Your code looks correct. I used the same approach for PurchTable table and it works. The only difference that PurchTable has overridden method canSubmitToWorkflow and SalesTable does not. So it could be CoC bug for non-overridden method with default parameters.

    Have you tried to rebuild model or do a full build?

    MS guide about canSubmitToWorkflow method docs.microsoft.com/.../how-to-enable-workflow-submission

  • Suggested answer
    Sukrut Parab Profile Picture
    71,741 Moderator on at

    Hi WWwong  ,

    You are getting error because salesTable does not have canSubmittoWorkflow method overridden. You can try instructions from following blog and see if it helps.

    community.dynamics.com/.../avoid-over-layering-in-development-of-workflows-on-existing-form

  • Community Member Profile Picture
    on at

    Hi all,

    It works on Form.

    Thanks

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 August 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 543 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
CU-1234529-002 Profile Picture

CU-1234529-002 188

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans