Complex approval workflow

Issue #754 resolved
Karo Salminen created an issue

Hi, could you help me with a complex workflow I’m trying to implement using JWT.

I'm speaking of a business approval process where the amount of approvals and assigned approver depends on the sum of euros. If sum (in custom field) is below 1000 euros, no approval is required. If sum is 2000 euros or over, level 1 approval is required. If sum is over 5000 level 2 approval is also required and if over 10000 euros level 3 in addition to level 2 and 1.

I've created following project properties in the project description: {1st level approvers=2000} {2nd level appprovers=5000}

I also created project roles: 1st level approvers, 2nd level approvers and 3rd level approvers.

I've created a Jira workflow which contains a transition "Submit for approval" that ends in status "Waiting for Approval". From that status there is a transition "Approve" to status "Approved". In addition from "Waiting for Approval" status there's a transition loop back to "Proceed to Next Approval" that is hidden from the user. The workflow should use the transition loop until all the required level of approvals is achieved and assign the issue to a member in corresponding project role (1st level approvers, 2nd level approves or 3rd level approvers). In case the amount of sum is below 2000 euros, no approval is required and the issue should transition from "Submit for approval" straight to "Approved" bypassing the status "Waiting for Approval"

Workflow.jpg

The post-functions rules for transitions "Submit for approval" and "Approve" are included as attachments. "Investoinnin suuruus" stands as the sum of euros, "Ensimmäisen asteen hyväksyjät" as 1st level approvers, "Toisen asteen hyväksyjät" as 2nd level approvers and "Kolmannen asteen hyväksyjät" as 3rd level approvers. "Viimeistelyssä" corresponds the status "Approved" and transition "Uusi hyväksyntä" corresponds "Proceed to Next Approval".

Submit for approval: Submit for approval.jpg

Approve: Approve.jpg

Comments (12)

  1. Fidel Castro Armario repo owner

    Hi @ karosalminen,

    Your approach to the approval workflow has various problems:

    1. You can't execute "Proceed to Next Approval" transition using a post-function in "Approve" transition, since the destination status of "Approve" is "Approved", and transition "Proceed to Next Approval" is not available in that status.

    2. Executing transitions on current issue (i.e., the issue that is being manually transitioned) through post-functions is not recommended, since you will need to refresh the browser in order to see the definitive status of the issue. The reason for that is that all the executions through post-function carried out in current issue are always executed with some delay, i.e., after manual transition has finished.

    I'm going to propose you an alternative approach in my next post.

  2. Fidel Castro Armario repo owner

    This is my proposal for the approval workflow. I'm going to use english names in it.

    This is the workflow:

    workflow.png

    We are going to create 2 custom fields:

    1. Numeric custom field called "Sum Of Euros". In my particular JIRA instance field Sum Of Euros uses field code {13300}.
    2. Checkboxes custom field called "Approvals" (not to be confused with JSD's Approvals field). This field will have 3 options: Level 1, Level 2 and Level 3, as shown in the following screenshot: Approvals Custom Field.png In my particular JIRA instance field Approvals uses field code %{13301}.

    We are going to use the following 3 project roles: Level 1 Approver, Level 2 Approver and Level 3 Approver.

    Transition "Proceed without Approval"

    1) Insert condition "Boolean condition with math, date-time or text-string terms" with the following configuration: conditions-proceed-without-approval.png Boolean expression is {13300} <= 2000.

    Transition "Submit for Approval"

    1) Insert condition "Boolean condition with math, date-time or text-string terms" with the following configuration: conditions-submit-for-approval.png Boolean expression is {13300} > 2000.

    Transition "Give Approval"

    1) Insert condition "Boolean condition with math, date-time or text-string terms" with the following configuration: conds-give-approval.png Boolean expression is

    {13300} > 2000 AND %{13301} !~ "Level 1" AND isInRole(%{00020}, "Level 1 Approver") OR
    {13300} > 5000 AND %{13301} ~ "Level 1" AND %{13301} !~ "Level 2" AND isInRole(%{00020}, "Level 2 Approver") 
    

    2) Insert post-function "Set a field as a function of other fields" with the following configuration: post-give-approval.png Setting rules are:

    [isInRole(%{00020}, "Level 1 Approver")]+ Level 1
    [isInRole(%{00020}, "Level 2 Approver")]+ Level 2
    

    Don't forget of check "Evaluate all the setting rules".

    Transition "Give Definite Approval"

    1) Insert condition "Boolean condition with math, date-time or text-string terms" with the following configuration: conds-definitive-approval.png Boolean expression is

    {13300} <= 5000 AND isInRole(%{00020}, "Level 1 Approver") OR
    {13300} > 5000 AND {13300} <= 10000 AND isInRole(%{00020}, "Level 2 Approver") AND %{13301} ~ "Level 1" OR
    {13300} > 10000 AND isInRole(%{00020}, "Level 3 Approver") AND %{13301} ~ "Level 1" AND %{13301} ~ "Level 2"
    

    2) Insert post-function "Set a field as a function of other fields" with the following configuration: post-definitive-approval.png Setting rules are:

    [isInRole(%{00020}, "Level 1 Approver")]+ Level 1
    [isInRole(%{00020}, "Level 2 Approver")]+ Level 2
    [isInRole(%{00020}, "Level 3 Approver")]+ Level 3 
    

    Don't forget of check "Evaluate all the setting rules".

  3. Karo Salminen Account Deactivated reporter

    Thanks! Do you mean by "Evaluate all the setting rules" the checkbox below? Evaluate.jpeg

    I can't select it for some reason.

  4. Fidel Castro Armario repo owner

    Yes, that's the parameter. The problem is that field "Approvals" should be a Checkboxes or Multi-Select field type. Sorry, I mistakenly wrote Radio Button. I have edited my previous post and corrected it.

  5. Karo Salminen Account Deactivated reporter

    Ok. Should the rules work with a checkbox also in Setting field as function of other field (Post-function for Give Approval)?

    [isInRole(%{00020}, "Level 1 Approver")]+ Level 1
    [isInRole(%{00020}, "Level 2 Approver")]+ Level 2
    

    I don't seem to get them work. The field "Approvals" should be set after Give Approval transition. However the field is empty (I put the field e.g. to edit view and none of the values are checked). I also tried the following rules:

    [isInRole(%{00020}, "Level 1 Approver")]"Level 1"
    [isInRole(%{00020}, "Level 2 Approver")]"Level 2"
    
  6. Fidel Castro Armario repo owner

    Hi @karosalminen,

    Yes, writing + Level 1 into a Radio Button or Multi-Select field will check option called Level 1, keeping the rest of values selected.

    I have tested a configuration similar to the one described in my proposal, and it works as expected. In my test I have used "Set a field as a function of other fields" post-function.

    Please, check the following:

    • You are not mistakenly using JSD's field Approvals, instead of the Checkbox custom field.
    • You are writing the names of the options exactly (i.e., respecting the case): Level 1, Level 2, etc.
    • You are writing the names of the project roles correctly, i.e., respecting the case.

    If none of the above is the cause of your problem, maybe the problem is that none of the setting rules are being activated. Please, try adding the following setting rule at the end: [true]+ Level 1, Level 3. That setting rule is always activated, and should add Level 1 and Level 3 to field Approvals.

  7. Log in to comment