Set default effort

📘

Effort is a role-specific field.

📘

How to apply this rule?

Set predefined effort for a newly created entity

Filter by Project.Name is optional

908908
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Task",
      "Bug",
      "Request",
      "UserStory",
      "TestPlan",
      "TestPlanRun"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": false
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "value": {
              "type": "constant",
              "value": "Custom Development"
            },
            "target": {
              "name": "Name",
              "type": "field",
              "target": {
                "name": "Project",
                "type": "field",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "operator": {
              "type": "is"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst roleEfforts = await api.queryAsync(\"RoleEffort\", {\n  select: \"{id,role:role.name}\",\n  where: \"assignable.id=\" + args.ResourceId\n});\n\nconst efforts = {\n  \"Developer\": 5,\n  \"QA Engineer\": 1\n}\n\nreturn roleEfforts.map(roleEffort => {\n  return {\n    command: \"targetprocess:UpdateResource\",\n    payload: {\n      resourceType: \"RoleEffort\",\n      resourceId: roleEffort.id,\n      fields: {\n        effort: efforts[roleEffort.role] || 0\n      }\n    }\n  };\n})"
  }
]

Set effort based on a custom field value (T-shirt size)

710710

Filter by Project.Name is optional

908908
[
  {
    "type": "source:targetprocess:EntityChanged",
    "entityTypes": [
      "Task",
      "Bug",
      "Request",
      "UserStory",
      "TestPlan",
      "TestPlanRun"
    ],
    "modifications": {
      "created": true,
      "deleted": false,
      "updated": [
        "TShirt Size"
      ]
    }
  },
  {
    "or": [
      {
        "and": [
          {
            "target": {
              "type": "field",
              "name": "Name",
              "target": {
                "type": "field",
                "name": "Project",
                "target": {
                  "type": "pipelineBlockOutput"
                }
              }
            },
            "value": {
              "type": "constant",
              "value": "Custom Development"
            },
            "operator": {
              "type": "is"
            }
          }
        ]
      }
    ],
    "type": "filter:Relational"
  },
  {
    "type": "action:JavaScript",
    "script": "const api = context.getService(\"targetprocess/api/v2\");\nconst roleEfforts = await api.queryAsync(\"RoleEffort\", {\n  select: \"id\",\n  where: \"role.name=\\\"Developer\\\" and assignable.id=\" + args.ResourceId\n});\nif (!roleEfforts || !roleEfforts[0]) { return; }\n\nconst sizes = {\n  \"S\": 1,\n  \"M\": 3,\n  \"L\": 5,\n  \"XL\": 10\n}\n\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: \"RoleEffort\",\n    resourceId: roleEfforts[0],\n    fields: {\n      effort: sizes[args.Current[\"TShirt Size\"]] || 0\n    }\n  }\n};"
  }
]