Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

Modify Purchase Requisition workflow in D365 F&O

(0) ShareShare
ReportReport
Posted on by 752

Hi Everyone,

I am using Purchase Requisition workflow which has been designed as shown in below image.

However, now my client has requirement that until and unless created RFQ doesn't have its Status High as Accepted, the User should not be able to click on Submit RFQ step of workflow as shown in 2nd image below.

I will be considering StatusHigh field of PurchRFQCaseTable.

RFQ is mentioned in Purchase Requisition line. PurchReqLine table's PurchRFQCaseId field.

In one Purchase Requisition there will be only one line.

If there is an alternative solution then do suggest it. I just don't want to allow user to Submit RFQ step until and unless the RFQ has not been accepted.

How this requirement can be achieved? Do I need to modify any classes or Table method for this? Or it can be handled through Workflow design?

Please suggest solution on same. I have never designed any workflow before. The current workflow has been configured by functional consultant.

PR_5F00_Workflow.png

PR02.png

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    You're welcome!

  • Rhushikesh R Profile Picture
    752 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Well both approaches seem to be valid,

    1. canSubmit method on PurchReqTable

    2. CoC of PurchReqWorkItemActionManager

    Thanks a lot once again for valuable and prompt response Gunjan. :)

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Ah.. Ok. I thought the user would not be allowed to submit in case the status was not Accepted and disabling the button took care of it. I didn't know that you had to throw an error.

  • Suggested answer
    Rhushikesh R Profile Picture
    752 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Gunjan,

    Actually I tried returning default false in canSubmit  and after building model it worked this time.

    But however it was causing Workflow to stop in between and I had to resume it manually from Workflow history.

    Hence, I debugged the code for standard condition and found one class which has all the logic related to Workflow submission named "PurchReqWorkItemActionManager".

    My requirement was not to disable the menu item but to throw error to user if the Status is not accepted. And I written below CoC, which works perfectly as per my requirement.

    Thanks a lot for your all valuable replies which helped me to explore more methods.

    [ExtensionOf(classStr(PurchReqWorkItemActionManager))]
    
    final class SimahPurchReqWorkItemActionManager_Extension
    
    {
    
        public static boolean validate(Common _common, Args _args)
    
        {
    
            PurchReqLine purchReqLine;
    
            PurchRFQCaseTable purchRFQCaseTable;
    
            boolean ret = true;
    
            ret = next validate(_common, _args);
    
            switch (_common.TableId)
    
            {
    
                case tableNum(PurchReqTable):
    
                    PurchReqTable purchReqTable = PurchReqTable::find(_common.RecId);
    
                    if (purchReqTable.RecId && ret)
    
                    {
    
                        select firstonly PurchRFQCaseId from purchReqLine where purchReqLine.PurchReqTable == purchReqTable.RecId;
    
                        if (purchReqLine.PurchRFQCaseId)
    
                        {
    
                            purchRFQCaseTable = PurchRFQCaseTable::find(purchReqLine.PurchRFQCaseId);
    
                            if (purchRFQCaseTable.StatusHigh != PurchRFQStatus::Accepted)
    
                            {
    
                                throw error("This action cannot be completed because no requests for quotations for this purchase requisition has been accepted.");
    
                                ret = false;
    
                            }
    
                        }
    
                    }
    
                    break;
    
            }
    
            return ret;
    
        }
    
    }

    Success01.png

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Rhushikesh,

    Not sure if it's your environment. Can you you try the same code on the other environment and check if that works for purchase requisitions?

  • Rhushikesh R Profile Picture
    752 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Gunjan, that too did not work. It seems something wrong with the setup or what?

    Because I tried returning false conditionally for PurchTable canSubmitWorkflow method on another environment and that worked perfectly.

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Rhushikesh,

    Can you try the CoC on canSubmit method and try returning false?

  • Rhushikesh R Profile Picture
    752 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Gunjan,

    I tried returning false and built the model. However, workflow button is still enabled.

    I see cansubmitToWorkflow method on PurchReqTable form as well. From there also, I tried returning false. But somehow it doesn't work.

    In my case submitting user and approver user are same for testing purpose. Is it happening because of this?

  • Gunjan Bhattachayya Profile Picture
    35,421 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Hi Rhushikesh

    Let's do a quick check. I have set the return to false so that the workflow button is not enabled.

    [ExtensionOf(tableStr(PurchReqTable))]
    final class SimahPurchReqTbl_Extension
    {
        public boolean canSubmitToWorkflow(str _workflowType)
        {
            PurchReqLine purchReqLine;
            PurchRFQCaseTable purchRFQCaseTable;
            boolean ret;
    
            ret = next canSubmitToWorkflow(_workflowType);
    
            if (_workflowType == workFlowTypeStr(PurchReqReview))
            {
                select purchReqLine
                    join purchRFQCaseTable
                        where purchRFQCaseTable.rfqCaseId       == purchReqLine.PurchRFQCaseId &&
                              where purchReqLine.PurchReqTable  == this.RecId;
                select * from purchReqLine where purchReqLine.PurchReqTable == this.RecId;
                if (purchRFQCaseTable && purchRFQCaseTable.StatusHigh != PurchRFQStatus::Accepted)
                {
                    ret = false;
                }
            }
            //return ret;
            return false;
        }
    
    }

    Please check after a full build of your model and check if the workflow button is disabled. This will prove that the CoC is working.

  • Rhushikesh R Profile Picture
    752 on at
    RE: Modify Purchase Requisition workflow in D365 F&O

    Here's the code Gunjan,

    [ExtensionOf(tableStr(PurchReqTable))]
    
    final class SimahPurchReqTbl_Extension
    
    {
    
        public boolean canSubmitToWorkflow(str _workflowType)
    
        {
    
            PurchReqLine purchReqLine;
    
            PurchRFQCaseTable purchRFQCaseTable;
    
            boolean ret = true;
    
            ret = next canSubmitToWorkflow(_workflowType);
    
            info("CoC called");
    
            if (_workflowType == workFlowTypeStr(PurchReqReview))
    
            {
    
                select * from purchReqLine where purchReqLine.PurchReqTable == this.RecId;
    
                if (purchReqLine.PurchRFQCaseId)
    
                {
    
                    purchRFQCaseTable = PurchRFQCaseTable::find(purchReqLine.PurchRFQCaseId);
    
                    if (purchRFQCaseTable.StatusHigh != PurchRFQStatus::Accepted)
    
                    {
    
                        warning("Cannot submit RFQ as RFQ status is not accepted.");
    
                        ret = false;
    
                    }
    
                }
    
            }
    
            return ret;
    
        }
    
    }

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
Martin Dráb Profile Picture

Martin Dráb 286 Most Valuable Professional

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 270

#3
Adis Profile Picture

Adis 174 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans