vRA Approval Policy for a specific custom field

Some times ago a customer asked me whether it is possible to create an approval policy for a specific filed in the vRA custom form. The customer has created a custom form where the requester can request a firewall rule. For this the customer can add a port and the customer wants to get an approval is the port field is not empty and if it empty then they want not get an approval email. I have thinking about it and follow you can find my solution.

I have created a vRealize Orchestrator Workflow which will be triggert later on by a vRealize Automation subscription. The workflow get the port field value from the inputProperties and if the port value not empty I will create a approval policy on demand. After this I will check whether the policy was created. If the policy hass been created, then I will wait for a short time and then the policy will be deleted.

Here is the Workflow Schema:

Here is the code where you can get the custom field value:

if(inputProperties){
    deploymentId = inputProperties.deploymentId
    var inputs = inputProperties.requestInputs 
    port = null
    if(inputs.port) port = inputs.port
    policyName = deploymentId
    actions = ["Deployment.Create"]
    approveExpire = 7
    approvers = inputs.approvers
    autoApprove = "APPROVE"
    level = 1
    policyId = null
    criteria = {
        "matchExpression": {
            "and": [{
                    "key": "catalogItemId",
                    "operator": "eq",
                    "value": inputProperties.catalogItemId
                }, {
                    "key": "deploymentId",
                    "operator": "eq",
                    "value": deploymentId
                }
            ]
        }
    }
    criteria = JSON.stringify(criteria)
}
System.debug("Deployment ID: " + deploymentId)

The port field is the port which was requested and the approver field is a array/string list with the name of the approvers e.g. USER:configadmin or GROUP:yourActiveDirectoryGroup

Here is the example custom form as YAML

layout:
  pages:
    - id: page_042qpv26
      sections:
        - id: section_project
          fields:
            - id: project
              display: dropDown
              signpostPosition: right-middle
        - id: section_deploymentName
          fields:
            - id: deploymentName
              display: textField
              signpostPosition: right-middle
        - id: section_10h68bgf
          fields:
            - id: port
              display: decimalField
              state:
                visible: true
                read-only: false
              signpostPosition: right-middle
        - id: section_3fnq7uz1
          fields:
            - id: approvers
              display: array
              state:
                visible: true
                read-only: false
              signpostPosition: right-middle
      title: General
schema:
  project:
    label: Project
    type:
      dataType: string
      isMultiple: false
    valueList:
      id: projects
      type: scriptAction
    constraints:
      required: true
  deploymentName:
    label: Deployment Name
    type:
      dataType: string
      isMultiple: false
    constraints:
      required: true
      max-value: 900
  port:
    label: port
    type:
      dataType: decimal
    constraints:
      required: false
  approvers:
    label: approvers
    type:
      dataType: string
      isMultiple: true
    constraints:
      required: false
options:
  externalValidations: []

Here is the workflow package:

Similar Posts

Leave a Reply

Your email address will not be published.

WC Captcha − 3 = 1