Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

Custom Workflow Button Not Appear in Form

(0) ShareShare
ReportReport
Posted on by 1,204

Hi,

This is my first time creating a custom workflow.

I was referring to this article to create custom workflow for SalesTable https://devmusings.blog/2018/03/18/custom-workflows-in-microsoft-dynamics-365-for-operations/

I added canSubmitToWorkflow() & updateWorkflowStatus() method on SalesTable using CoC.

Submit menu item points to correct submit manager class.

In SalesTable form, I already modified Workflow Data Source, Workflow Enabled & Workflow Type properties.

However, the workflow button is not appearing when I open the form.

What else do I need to verify?

Thank you.

  • Suggested answer
    HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    Apparently, there's standard code that show/hide the button in SalesTable form:

    /// 
        /// Check if workflow action button will be displayed.
        /// 
        /// 
        /// Workflow type.
        /// 
        /// 
        /// Return true if any line needs to submit and not submitted.
        /// 
        public boolean canSubmitToWorkflow(str _workflowType = '')
        {
            boolean ret;
            MCRSalesLine mcrSalesLineLocal;
            SalesLine salesLineLocal;
    
            if (mcrSalesLine)
            {
                // if current line is not submitted or approved
                if (mcrSalesLine.RetailPriceOverrideWorkflowState == RetailPriceOverrideWorkflowState::NotSubmitted || mcrSalesLine.RetailPriceOverrideWorkflowState == RetailPriceOverrideWorkflowState::Approved || mcrSalesLine.RetailPriceOverrideWorkflowState == RetailPriceOverrideWorkflowState::None)
                {
                    // and if any non submit line is need to submit for approval
                    select firstonly RecId from mcrSalesLineLocal
                        join RecId from salesLineLocal
                            where mcrSalesLineLocal.SalesLine == salesLineLocal.RecId && salesLineLocal.SalesId == salesTable.SalesId
                                && mcrSalesLineLocal.RetailPriceOverrideWorkflowState == RetailPriceOverrideWorkflowState::NotSubmitted;
    
                    if (mcrSalesLineLocal)
                    {
                        ret = true;
                    }
    
                }
            }
    
            // hide workflow action button even if the line is rejected and the line's status is None and no not submitted lines
            element.design().controlName("WorkflowActionBarButtonGroup").visible(ret || mcrSalesLine.RetailPriceOverrideWorkflowState != RetailPriceOverrideWorkflowState::None);
    
            return ret;
        }

    Here's my updated extension. This able to show the workflow button as expected:

    public boolean canSubmitToWorkflow(str workflowtype)
        {
            boolean     canSubmit = false;
            
            canSubmit = next canSubmitToWorkflow(workflowtype);
            
            canSubmit = SalesTable.canSubmitToWorkflow();
    
            this.design().controlName("WorkflowActionBarButtonGroup").visible(this.design().workflowEnabled());
            
            return canSubmit;
        }

    Regards.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    Hi Junaid,

    Workflow methods on SalesTable table extension:

    [ExtensionOf(tablestr(SalesTable))]
    final class SalesTable_WorkflowTest_Extension
    {
        public boolean canSubmitToWorkflow(str workflowType)
        {
            boolean     canSubmit = false;
    
            canSubmit = next canSubmitToWorkflow(workflowType);
    
            if (this.RecId && this.WorkflowState  == VersioningDocumentState::Draft)
            {
                canSubmit = true;
            }
            return canSubmit;
        }
    
        public static void updateWorkflowStatus(RecId _documentRecId, VersioningDocumentState _status)
        {
            ttsbegin;
        
            SalesTable salesTable;
        
            update_recordset salesTable
            setting WorkflowState = _status
            where salesTable.RecId == _documentRecId;
        
            ttscommit;
        }
    
    }

    Workflow type properties:

    salestabletemplate.png

    SalesTableListPage form extension properties:

    salestablelistpage-property.png

    Workflow button is displayed and working fine in SalesTableListPage:

    salestablelistpage.png

    SalesTable form extension properties:

    salestable-property.png

    Although Workflow Enabled set to Yes, Workflow Type is specified, workflow button is not showing in SalesTable form:

    salestable.png

    What am I missing? Thank you.

  • Suggested answer
    RE: Custom Workflow Button Not Appear in Form

    Hi HAIRUL HAZRI,

    Yes we don't have Activate change management option for Sales Order workflow, it's only at Procurement and sourcing part.  

    Can you please share some screen prints of an error to better understanding.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    New update.

    For SalesTableListPage , everything is OK now. I can submit the workflow, approve, reject, delegate, request to change, cancel

    successfully.

    However, the workflow button still not appears in SalesTable form. I still cant find what I did wrong or where else to verify.

    Is it the Document Menu Item in Workflow Type? SalesTable display menu item should be the correct one, am I right?

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    Not exactly everything is OK.

    SalesTableListPage form displays the workflow button, but when I try to submit, I get "Function WorkflowWorkItemActionDialog.run has been incorrectly called." error.

    SalesTable form not displaying the workflow button.

    I already added canSubmitToWorkflow  to SalesTable table using CoC as mentioned above. Do I need to add in other than SalesTable table?

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Custom Workflow Button Not Appear in Form

    So, for SalesTableListPage , everything is OK. not for SalesTable?

    Have you also added canSubmitToWorkflow  to SalesTable?

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    Active change management in Procurement & Sourcing parameters is enabled.

    But supposedly this is only applicable for Purchase order workflow right? I don't see Active change management in Sales and marketing parameters, Accounts receivable parameters.

    And another thing, seems like the workflow button is displayed in SalesTableListPage form, but not in SalesTable form.

    Even though both forms have enable the same workflow. Any idea why this happened?

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Custom Workflow Button Not Appear in Form

    Hi Sir,

    Check this : community.dynamics.com/.../workflow-button-is-not-displaying-on-a-form

    I mean AOS services.

  • HAIRUL HAZRI Profile Picture
    HAIRUL HAZRI 1,204 on at
    RE: Custom Workflow Button Not Appear in Form

    Hi Blue Wang,

    The canSubmitToWorkflow method is not triggered. What did I miss in this case?

    By restart services, you mean which services?

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: Custom Workflow Button Not Appear in Form

    Hi HAIRUL HAZRI ,

    Have you debugged canSubmitToWorkflow method? and pass parameter?

    If everything is ok, please restart services.

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

Congratulations 2024 Spotlight Honorees!

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December!

Congratulations to our December super stars! 🥳

Get Started Blogging in the Community

Hosted or syndicated blogging is available! ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,642 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,371 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans