> For the complete documentation index, see [llms.txt](https://docs.agilecase.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.agilecase.com/developer-documentation/case-scripting/on-load-scripts/custom-messages-within-cases.md).

# Custom Messages Within Cases

This example demonstrates a script that displays 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 to identify your particular fields and values and to display your own custom messages.

### Script

#### Custom Messages Within Cases

```javascript
// If you are adapting this script for use on your own system, "Customer Rating" should be changed to the name or ID of your own field.
$.get('/api/case/' + caseid + '/data?getValues=Custom.CustomerRating', function( data ) {
	
var value = data.data.customFields[0].value;

// The value that triggers the script should be edited to one that is relevant to your chosen field	
if (value < 50){
// You can specify the message you want to display when the criteria are satisfied here by editing the existing message
		$('#scriptingTarget').html('<div class="alert alert-danger"><i class="icon-info-sign"></i> This Customer has a negative rating</div>');
// The "else" function signifies that what follows is the message that will be displayed if the criteria are not met
	} else {
// You can edit the format of your message by changing "alert-success" to another formatting option
		$('#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 displays a different message depending on the value of a "customer rating" field. If the value is below 50, the user is presented with a warning that the customer has a poor reputation. If it is above 50, a prompt reminds the user that the customer has a good reputation.

The following sections display the messages that appear if the value of the field does or does not fulfill your specified criteria.

### If the value is over 50

<figure><img src="/files/AS9TDgBG0Gmav4kluL9U" alt=""><figcaption></figcaption></figure>

If the value of the "Customer Rating" field is over 50, a message informing the user of the customer's good reputation is displayed:

<figure><img src="/files/y4WTmEyZnrl4Xx99qE4R" alt=""><figcaption></figcaption></figure>

### If the value is under 50

<figure><img src="/files/adC1oaFcFBzu2ZbXwlod" alt=""><figcaption></figcaption></figure>

When the value of the field is changed to a number below 50, an alternate message warning the user of the customer's bad reputation is displayed:

<figure><img src="/files/KuUpNBCcPf8gg0b5RTuU" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.agilecase.com/developer-documentation/case-scripting/on-load-scripts/custom-messages-within-cases.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
