Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Version History

« Previous Version 5 Current »

This example will demonstrate a script that will display a custom message in a case depending on the value of a specified field.

This code can be copied and used in your own system, however, it must be edited in order to identify your particular fields and values and to display your own custom messages.

Script

 

Custom Messages Within Cases
$.get('/api/case/' + caseid + '/data?getValues=Custom.CustomerRating', function( data ) {
	
var value = data.data.customFields[0].value;
	
if (value < 50){
		$('#scriptingTarget').html('<div class="alert alert-danger"><i class="icon-info-sign"></i> This Customer has a negative rating</div>');
	} else {
		$('#scriptingTarget').html('<div class="alert alert-success"><i class="icon-info-sign"></i> This Customer has a positive rating</div>');
	}
});

 

This code block contains a script that will display a different message depending on the value of a "customer rating" field. If the value is below 50 then the user will be presented with a warning that the customer has a poor reputation, if it is above 50 then a prompt will remind the user that the customer has a good reputation. 

The first line of code specifies the field in which the script will look for a value. In the case the field name is "CustomerRating". If you are adapting this script for use on your own system, this should be changed to the name or ID of your own field.

The next line sets the condition. In this case "if (value <50", which means that an action will be taken if the value of your specified field is less than 50. This line can be configured so that the value is relevant to your chosen field.

The following section displays the messages that will be displayed if the value of the field does or does not fulfill your specified criteria.

 

If the value is over 50

 

 

If the value of the "Customer Rating" field is over 50, then a message informing the user of the customers good reputation will be displayed:

 

 

 

You can edit the content of the message in the code by replacing the text in the example.

 

 

If the value is under 50

 

 

When the value of the field is changed to a number below 50, an alternate message that warns the user of the customers bad reputation will be displayed:

 

 

In the code, this second message is divided by the first with the "else" function. This causes the next line of code to be triggered if the value is different to that specified for the first action. 

It is also possible to edit the format of the messages that will be displayed. In his example the formatting controls are "alert-success" and "alert-danger". 

"alert-success" will display the former green text box intended for confirming a successful action or a positive result.

whilst "alert-danger" will display the latter in red and is suitable for warnings or notifications that criteria have not been met.

 
  • No labels