
Wait for Condition
The Wait for Condition workflow activity allows you to specify either a simple condition (using the condition builder), or a script. Unlike a normal javascript function (but similar to many similar script fields in ServiceNow, the aim of this script is not to return anything, but to set a pre-defined variable (called answer) to either true or false. You can do just about anything you can do in any server-side script, but whatever that variable is set to after the script finishes running, will be the result:
One thing to keep in mind about the Wait for Condition workflow activity, is that it is only (re-)evaluated when the record that the workflow is associated with, is updated. Any update will trigger the re-evaluation of this condition, but updating another record will not. To help us understand this, let's imagine the following scenario:
Imagine that you've got a workflow associated to an Incident ticket, and that workflow runs a script which generates another outside record in a custom table that extends Task [task]. Next, the workflow transitions to the Wait for Condition activity. The Wait for Condition activity is configured to wait until that outside record is closed, which it determines via a script. However, the Incident workflow won't have any idea that you've updated the outside record once it is closed, so you'll need to give the incident a little nudge to get it to re-run the evaluation script.
One effective way of solving this problem, is to associate these two tasks together, and then use a business rule to update the parent record. For example, when generating the record in the custom task table, you can populate the Parent [parent] field with a reference to the record that the workflow is running on. You can then use a business rule on that custom table, that runs when it's closed, and updates the parent record by adding a work note. That will effectively nudge the record, and the workflow will re-evaluate the condition.
As with most records that have both a Condition builder field, and a Condition script field, those fields in the Wait for Condition activity must both evaluate to true, if used.