/
5.21.4.3.2 - Add Task
5.21.4.3.2 - Add Task
This example will show you how to use an on save script to add a task to your system when a value in a specified field is changed.
The script can be copied out and modified with your own field IDs and tasks in order to use it within your own system.
Script
Add Task
// The first line specifies the field you want the script to depend on [Changed.CustomField(6364).Changed] function on_save() { // Here you can specify the value that you wish to trigger the first task if(Changed.CustomField("6364").NewValueAsNumber <= 50){ // The format for adding as task is: Description, Note, Assigned User, Number of days until task is due Service.AddTask("Blacklist Client", "Suspend client license", Service.Case.FeeEarner, 7); Service.AddMessage("Task successfully added", "notify-success"); // return true specifies that the data created by the script will be saved to the system when it has been run return true; // This section specifies the alternative value that will trigger the second task as well as the content of that task } else if(50 < Changed.CustomField("6364").NewValueAsNumber < 100){ Service.AddTask("Reinstate Client", "Reinstate client license", Service.Case.FeeEarner, 7); Service.AddMessage("Task successfully added", "notify-success"); return true; // The section below creates an error message that will be send if the value in the field is invalid // i.e it does not meet the criteria for either task to be created } else { Service.AddMessage("An error occurred while adding task", "notify-error"); // return false means that the data create will not be saved to the system // in this case it means that the error message will be displayed, but not saved. return false; } }
The script above will create a task whenever the "Customer Rating" field is modified to either above or below 50.
Task created
When the value of the field is changed and the case is saved, the notification message you created will let you know that the task has been added.
Tasks in case
The new tasks will be saved under the "Tasks" tab on the case page.