global.beforeValidation
$().beforeValidation is a page-level lifecycle hook that fires just before the agent saves a disposition (submits the script page). It gives you a chance to run custom validation logic, make API calls, or update field values — and optionally block the save by returning false.
$().beforeValidation = function(disposition) {
// your logic here
// return false to block saving
};
Parameters
| Name | Type | Description |
|---|---|---|
| comment | {String} | the comment written by the agent |
| disposition | {Object} | the selected disposition |
Disposition object
| Key | Type | Description |
|---|---|---|
| dispositionId | {Int} | Optional. The desired disposition that overwrites the one that the agent selected. |
| label | {String} | Display label of the selected disposition |
| description | {String} | Optional. The description of the disposition event that overwrites the one selected by the agent. |
| next_calldate | {String} | Optional. You can specify the callback time. It has only an effect if the selected disposition is a callback. Format: ISO 8601, YYYY-MM-DDTHH:MM:SS |
| assesment | {String} | Assessment category. |
Returns
| Type | Comment |
|---|---|
| {Boolean} | If true, disposition is allowed; if false, disposition isn’t allowed |
| {Object} | Disposition object |
Tip: Always pair
return falsewith analert()call so the agent knows why the save was blocked.
Common use cases
Use case 1 Validate callback date
Prevent agents from scheduling a callback for any day other than today:
$().beforeValidation = function(disposition) {
if (disposition.id === 1 || disposition.id === 2) {
var callbackDate = disposition.next_calldate.slice(0, 10);
var today = new Date().toJSON().slice(0, 10);
if (callbackDate !== today) {
alert('Callback must be scheduled for today only!');
return false;
}
}
};
Use case 2 Block save based on assessment type
Run a server-side check before allowing an “Ordered” disposition through:
$().beforeValidation = function(disposition) {
if (disposition.assesment === vcc.DISPOSITION_ORDERED) {
var xhr = vcc.httpRequest();
var numberid = vcc.getScriptVariable('numberid');
var projectid = vcc.getScriptVariable('projectid');
xhr.open('GET', 'https://your-api.example.com/check?numberid=' + numberid + '&projectid=' + projectid, false);
xhr.send();
var result = JSON.parse(xhr.responseText);
if (!result.valid) {
alert('Order validation failed. Please review the record.');
return false;
}
}
};
Use case 3 Sync field data to an external system before saving
Write back updated contact info to a CRM before the disposition is committed:
$().beforeValidation = function(disposition) {
var projectid = vcc.getScriptVariable('project.id');
var numberid = vcc.getScriptVariable('numberid');
var contact = {
name: vcc.getFieldValue('name'),
phone: vcc.getFieldValue('phone1'),
email: vcc.getFieldValue('email'),
};
vcc.callCustomerApi(
'PUT',
'/v2/projects/' + projectid + '/records/' + numberid + '/contacts/1',
contact,
function(success, response) {}
);
};
Use case 4 Restore a field value before saving
Ensure a field is never left blank when the agent saves:
$().beforeValidation = function() {
if (vcc.getFieldValue('phone1') === '') {
vcc.setFieldValue('phone1', original_phone);
}
};
Notes
$().beforeValidationapplies to the entire page, not a specific component. Usedisposition.idordisposition.assesmentto limit logic to specific dispositions.- Only one
$().beforeValidationhandler can be active per page. Defining it multiple times will overwrite the previous definition. - The
dispositionparameter isundefinedif called in contexts outside a normal disposition save — guard accordingly.
Comments
Can’t find what you need? Use the comment section below to connect with others, get answers from our experts, or share your ideas with us.
There are no comments yet.