Update Team State of the Entity when a Team is assigned to it

The main idea of the rule is to modify the Team Assignment. This is an entity that is created when you assign Team to Entity. It has its own EntityState attribute which is also called "Team State". More details:
https://md5.tpondemand.com/api/v1/TeamAssignments/meta

In order to change Team State, you need to send a POST query to the TeamAssignment endpoint. You need to define Team Assignment ID and Entity State ID.

After you apply the rule from the example update the first and second line in the code with the corresponding values for Team Name and Team State Name

913
{
  "pipeline": [
    {
      "type": "source:targetprocess:EntityChanged",
      "entityTypes": [
        "UserStory"
      ],
      "modifications": {
        "created": false,
        "deleted": false,
        "updated": [
          "AssignedTeams"
        ]
      }
    },
    {
      "type": "filter:targetprocess:Team",
      "teamIds": [
        644
      ],
      "supportManyTeams": false
    },
    {
      "type": "action:JavaScript",
      "script": "const teamState = 'To Be Tested'; // Set name of the Team State you would like to set for an entity\nconst teamName = 'Quality Assurance'; // Set name of the Team that corresponds to the Team Workflow of the Team State above\n\nconst api = context.getService(\"targetprocess/api/v2\");\nconst teamAssignment = await api.queryAsync('TeamAssignment', {\n  where: `Assignable.Id = ${args.ResourceId} and Team.Name = \"${teamName}\"`,\n  select: `{id:Id, teamStateId:EntityState.NextStates.Where(Name = \"${teamState}\").Select(Id).First()}`\n});\nif (!teamAssignment || teamAssignment.length === 0 || !teamAssignment[0].teamStateId) {\n  console.log('There is either incorrect Team Name or Team State defined');\n  return;\n}\nreturn {\n  command: \"targetprocess:UpdateResource\",\n  payload: {\n    resourceType: 'TeamAssignment',\n    resourceId: teamAssignment[0].id,\n    fields: {\n      EntityState: {Id: teamAssignment[0].teamStateId}\n    }\n  }\n};\n"
    }
  ]
}

What’s Next

See how to apply the raw JSON on the page below