This example will show you how to use scripts to update custom fields.
Script
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// The first line specifies the field you want the script to depend on [Changed.CustomField(6364).Changed] function on_save() { // The line below specifies that the script will run when value of the field is 50 or below if (Changed.CustomField("6364").NewValueAsNumber <= 50) { // The section below picks out a custom field and specifies what the value should be changed to // and adds a system message to notify the user that the change has taken place //The format for updating a custom field is "Service.UpdateCustomField("Field name or ID", "Value") Service.UpdateCustomField("6390", "Decline"); Service.AddMessage("Custom field successfully updated", "notify-success"); return true; //This section specifies how the field should be updated if the value is above 50 //a different custom field can be specified here if you want to update a separate field } else if (50 < Changed.CustomField("6364").NewValueAsNumber < 100) { Service.UpdateCustomField("6390", "Proceed"); Service.AddMessage("Custom field successfully updated", "notify-success"); return true; //The script below triggers an error message if neither of the criteria above are satisfied } else { Service.AddMessage("An error occurred while updating custom field", "notify-error"); return false; } } //Service.UpdateCustomField(string nameOrId, string newValue), where nameOrId - name or id of custom field |
...