Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titleUpdate Custom Field Information
linenumberstrue
// 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" means that the new data will be stored in your system while "return false" signifies that the new data will not be saved
        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

...