Versions Compared

Key

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

The example below will show you how to use scripting to update case information depending on the value held by a custom field.

Script

 

Code Block
languagejs
titleUpdate Case Information
linenumberstrue
// The first line specifies the field you want the script to depend on
[Changed.CustomField("val_a"6364).Changed]

function on_save() {
// The section below specifies a case field and the value it should be changed to if
// the custom field holds a value below 50
    if (Changed.CustomField("val_a6364").NewValueAsNumber <= 50) {
		
// The format for updating case information is "Service.UpdateCaseInfo("statusField Name", "openValue");
		"
        Service.AddMessageUpdateCaseInfo("Case info successfully updatedstatus", "notify-successclose");
		
        Service.AddMessage("Case info successfully updated", "dialognotify-success", "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;
// The section below specifies the alternative value if the custom field holds a value above 50
    } else if (50 < Changed.CustomField("val_a6364").NewValueAsNumber < 100) {
		
        Service.UpdateCaseInfo("milestone.1142status", "1.1.2015open");
		
        Service.AddMessage("Case info successfully updated", "notify-success");
		Service.AddMessage("Case info successfully updated", "dialog-success", "Success");
		
        return true; 
// The script below triggers an error message if neither of the conditions above are satisfied.
    } else {
		Service.AddMessage("An error occurred while updating case info", "notify-error"); 		Service.AddMessage("An error occurred while updating case info", "dialognotify-error", "Error");
        return false;
    }
}

//Service.UpdateCaseInfo(string fieldName, string newValue)

 

 

Initial case information

Image Added

 

Here is the selected field in the case information panel before the value of the custom field is changed.

 

Notification message

 

Image Added

 

Once the value in the custom field has been changed, you will receive a notification that your information has been updated.

 

Updated case information

 

Image Added

 

Once the case has been refreshed, your case information will have changed to reflect the script.