Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Control workflow appro...
Finance forum
Answered

Control workflow approval based on field value

Posted on by 56

We have a requirement, in which our client has a form with multiple workflow approval steps. 

What we need- on the second step, the field needs to be mandatory for the approver to fill, before he can approve the record.
What we have done - on the second step, the field becomes mandatory meaning the user operations like save are halted unless the mandatory field is filled.

Problem:  The workflow approval is independent of the fact that the field is mandatory. So even if that mandatory field is empty, the user can approve the record and proceed with the next step in the workflow. 

Can we throw an error when the user tries to approve the record if the field is empty? 

Any suggestions for the same would be really helpful. 

  • Verified answer
    Tazeen Zaidi Profile Picture
    Tazeen Zaidi 56 on at
    RE: Control workflow approval based on field value

    The solution :

    We created a pre-event handler of the run method of the base class - WorkflowWorkItemActionManager

    And validated the workflow type and validated the required field.

  • Suggested answer
    Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Control workflow approval based on field value

    Hi Tazeen,

    Right, the conditions check whether it is fulfilled when you run the workflow. You should actually not be able to make a change in between, that is at the time the workflow runs. If you want to realize this in D365FO then you possibly need two workflows. An alternative is MS Flow where you have greater flexibility in designing and running workflows.

    Best regards,

    Ludwig

  • Tazeen Zaidi Profile Picture
    Tazeen Zaidi 56 on at
    RE: Control workflow approval based on field value

    Hi Maatguo,

    Thank you for your assistance, and reply.  

    I tried your suggestion - what happens is, this condition defines whether the step is created or not. Incase our case when the user does not fill the mandatory field and approves in that step, the condition is evaluated to false so the next work item creation is skipped, resulting in the workflow completion.

    We need to refrain the user from approving in case the mandatory field is not filled.

    Any suggestions would be really helpful.

  • MATTGUO Profile Picture
    MATTGUO 22,296 on at
    RE: Control workflow approval based on field value

    Hi Tazeen,

    You can add a condition on second step to check the field is filled in.

    7713.png

  • Tazeen Zaidi Profile Picture
    Tazeen Zaidi 56 on at
    RE: Control workflow approval based on field value

    The workflow is a custom one, so the event handlers for the approval update the workflow status of the form.

    In case we put the validation on the event handler, would the approver be restricted from approving? or would the thrown error reflect in the workflow history?

  • Tazeen Zaidi Profile Picture
    Tazeen Zaidi 56 on at
    RE: Control workflow approval based on field value

    The field, as well as the workflow, is a custom one.

    Exactly! Yes the second step approver (for example - a finance team member), needs to enter some value in the field and only then approve the record.

  • Ludwig Reinhard Profile Picture
    Ludwig Reinhard Microsoft Employee on at
    RE: Control workflow approval based on field value

    Hi,

    What 'field' is that? A standard one or one that you created?

    Do I understand it correctly that somebody has to fill this field during the second workflow step?

    Best regards,

    Ludwig

  • sohaibcheema Profile Picture
    sohaibcheema 46,592 User Group Leader on at
    RE: Control workflow approval based on field value

    workflow approval happens using workflow event handler class. each workflow has its own class. in that class, you would find the code of approval. you can manage any validations there, before record is approved.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans