Troubleshooting: My Automation Rule is not working!

The first question to answer is What exactly is “not working”?
The log of the rule can help you to understand what has happened.

Option 1: the rule is not triggered at all (no records in the log)

Make sure that the rule is active and that the trigger is correct.
Make sure that the you have actually performed the action that corresponds to the trigger.

Option 2: the rule is triggered, but the filter did not match

Double-check the filter. Maybe the entity on which you are trying to run the rule does not actually match the filter?

The most popular filtering errors are:

  • Typo in the name (e.g. EntityState.Name is “InProgress”, while the state is called “In Progress”)
  • Using a filter by Process for the entities that do not have Process (global ExD entities, Assignments, Team Assignments, Comments, etc.)
  • Using a filter by ID for some non-work-item entities, and expecting the filter to be applied to the work item ID (e.g. to filter for a Comment added to an item #123 we need to filter by General.ID is 123, and not ID is 123)
  • Using a filter by non-required fields for Create trigger (the value was not yet there when the rule was triggered)
  • Using a filter by Responsible Team, when in fact they wanted to using a filter by Assigned Team (thus using a filter by Team)
448448

Option 3: the rule is triggered, but failed with an error

What is the error message?

Timeout

Either the rule is not written in an optimal way and it should be reworked, or the rule is making a call to an external resource which is too slow.
More about timeouts: https://dev.targetprocess.com/docs/automation-rules-limits-and-timeouts#automation-rules-timeouts

TpRestService HTTP request completed with non-2xx status code: BadRequest

10891089

The error message is usually very straightforward. You need to find the broken GET API call and to correct it:

TargetprocessApiException: HTTP server returned an error: BadRequest (Error during deserializing resource.)

11101110

Double-check the command that you've returned. Is it a valid POST API call?
More about troubleshooting API POST calls: https://dev.targetprocess.com/docs/troubleshooting-rest-issues#500-error-bad-request---for-post-requests

PipelineProcessingException: Value of the reference field should either be a numeric ID or an actual entity reference.

11111111

Trying to set an object (like EntityState, Release, Project, Team, etc.) using its name (instead of its ID).
You need to either use ID, or use another kind of action (MoveToState instead of Update).

TargetprocessApiException: Unable to execute command MoveToState

14151415

Check which exact entity the rule is trying to move to which exact state. Such error means that at least one of the parameters (resourceType, resourceId, stateName or stateKind is not valid). The most popular examples of invalid parameters are:

  • resourceType and resourceId are not coherent (e.g. resourceId is for a Bug, while resourceType says “UserStory”)
  • a state with stateName does not exist in the process for the entity with this resourceId
  • an entity with this resourceId does not exist
  • resourceType is not spelled properly (typo, extra space, term instead of the real name)

Active promises left: Execution completed but x of y promises created during execution left in unfulfilled state

11101110

There are several API calls that are done in parallel with Promise.all, and at least one of them is failing. Either fix the error in API call (if it is easy to find), or separate the calls to get a more meaningful error.

🚧

Do not forget to group the calls back to be executed in parallel once you have found and fixed the broken API call.

TargetprocessApiException: cannot execute on abstract resource

An attempt to update a custom field using “Assignable” or “General” as entity type. Here is an example of Javascript action that would produce such error:

const api = context.getService("targetprocess/api/v2");
const assignables = await api.queryAsync("Assignable", {
  select: `id`,
  where: "(EntityType.Name='UserStory' or EntityType.Name='Task') and Project.Process.Name='Kanban'"
});

return assignables.map(assignableId => ({
  command: "targetprocess:UpdateResource",
  payload: {
    resourceType: "Assignable",
    resourceId: assignableId,
    fields: {
      "Work Type": "Business Project"
    }
  }
}));

A proper way is to use exact entity type instead:

const api = context.getService("targetprocess/api/v2");
const assignables = await api.queryAsync("Assignable", {
  select: "{id,type:EntityType.Name}",
  where: "(EntityType.Name='UserStory' or EntityType.Name='Task') and Project.Process.Name='Kanban'"
});

return assignables.map(assignable => ({
  command: "targetprocess:UpdateResource",
  payload: {
    resourceType: assignable.type,
    resourceId: assignable.id,
    fields: {
      "Work Type": "Business Project"
    }
  }
}));

Invalid script: Unexpected token

552552

The syntax of the rule is not valid - usually it means that it was not copied properly. The most popular error is to take JSON code and then to paste it to Javascript action (instead of Raw JSON view). An attempt to modify the rule in Raw JSON view can also lead to such error. The correct action are:

  • to apply JSON code - follow the steps exact as described at How to apply Raw JSON from Examples
  • to modify the rule - switch back to UI (by clicking again on Raw JSON View) and only then add some modifications

ReferenceError: x is not defined

895895

In Javascript, just as in any other code, we have to define a variable before using it. Here is an example of Javascript action that would produce this error:

const api = context.getService("targetprocess/api/v2");
const count = await api.getByIdAsync(args.ResourceType, args.ResourceId, {
    select: "assignments.count"
});

return {
  command: "targetprocess:UpdateResource",
  payload: {
    resourceType: args.ResourceType,
    resourceId: userStoryId,
    fields: {
      Assigned: count
    }
  }
};

Type error: Cannot read property 'x' of null

11081108

Trying to read a field from an empty object. For example, if Feature is not set here, we'll get an error:

const api = context.getService("targetprocess/api/v2");
const feature = await api.getByIdAsync("Feature", args.Current.Feature.Id, {
    select: "{name,description}"
});

PipelineProcessingException: Action produced x intentions, which exceeds the allowed number of intentions per action

11801180

The limit for the number of actions performed by Javascript code is exceeded.
How many actions are you trying to perform with your rules? Can this number be reduced? Maybe several actions can be grouped together?

Option 4: the rule is triggered, action is executed with no errors, but the desired result is not achieved

  1. Try writing into the log some variables to help you with troubleshooting
  2. Try to split the rule into smaller parts to check where exactly the issue is
  3. If nothing helps - contact our Sales team at [email protected] to order customer development service, and our developers will adjust your Automation Rule for you