HomeGuidesRecipesAPI ExplorerForumSupport
Partner Portal
Partner Portal

Script examples

Explore scenarios to gain insights into how to customize the approval policies with practical situations, and adapt them to fit the distinctive needs and goals of your organization.

Examples

On this page, you will discover how to tailor your approval processes to your specific needs by looking into the practical side of customizing your approval policies.

Customization allows you to adapt the rules to fit your unique requirements, making your application's decision-making more efficient.

📘

Approval policies are designed using the MoniteScript. The conditions mentioned on this page must be inserted into the script field.


Conditional invoice approval

Conditional invoice approval

The approval policy below states that the approval of either one user OR two roles is required for an invoice to be approved:

"script": [
  {
    "if": {
      "any": [
       {
         "call": "ApprovalRequests.request_approval_by_users",
         "params": {
           "user_ids": [user_uuid_list],
           "required_approval_count": 1
         }
       },
       {
         "call": "ApprovalRequests.request_approval_by_roles",
         "params": {
           "role_ids": [role_uuid_list],
           "required_approval_count": 2
         }
       }
      ]
    },
    "then": ["{Payables.approve(invoice.id)}"],
    "else": ["{Payables.reject(invoice.id)}"]
  }
]

Mark invoice as paid

Mark invoice as paid

The approval policy below states that once the invoice is approved by two users AND two roles, it is marked as paid with the comment Marked from approval.:

"script": [
  {
    "if": {
      "all": [
        {
          "call": "ApprovalRequests.request_approval_by_users",
          "params": {
            "user_ids": [user_uuid_list],
            "required_approval_count": 2
          }
        },
        {
          "call": "ApprovalRequests.request_approval_by_roles",
          "params": {
            "role_ids": [role_uuid_list],
            "required_approval_count": 2
          }
        }
      ]
    },
    "then": ["{Payables.mark_as_paid(invoice.id, 'Marked from approval.')}"],
    "else": ["{Payables.reject(invoice.id)}"]
  }
]

Approval chains

Approval chains

The approval policy below is a structured sequence of approvals that occur in a particular order and depend on the previous condition:

"script": [
  {
    "if":{
      "any":[
        {
          "call":"ApprovalRequests.request_approval_by_users",
          "params":{
            "role_ids":[
              "random_user_and_role_uuid"
            ],
            "required_approval_count":1
          }
        }
      ]
    },
    "then":[
      {
        "if":{
          "all":[
            {
              "call":"ApprovalRequests.request_approval_by_roles",
              "params":{
                "role_ids":[
                  "random_user_and_role_uuid"
                ],
                "required_approval_count":1
              }
            }
          ]
        },
        "then":[
          "{Payables.approve(invoice.id)}"
        ],
        "else":[
          "{Payables.reject(invoice.id)}"
        ]
      }
    ],
    "else":[
      "{Payables.reject(invoice.id)}"
    ]
  }
]