ServiceNow Examples · LessonBy Praveen T, ServiceNow Trainer, 9 yrs · Published · current release · reference
Client script examples
onChange, onLoad and onSubmit client script patterns.
Quick answer
Client Scripts react to form events in the browser. Keep them light and never trust them for security.
Key takeaways
- onChange: react to a field
- onLoad: default a field
- onSubmit: validate
Client Scripts react to form events in the browser. Keep them light and never trust them for security.
onChange: react to a field
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') return;
g_form.setValue('urgency', newValue);
}onLoad: default a field
function onLoad() {
if (g_form.getValue('category') === '')
g_form.setValue('category', 'inquiry');
}onSubmit: validate
function onSubmit() {
if (g_form.getValue('short_description') === '') {
g_form.addErrorMessage('Description is required');
return false;
}
}Quick check
+0 XPStreak ×0
Question 1 of 2
Where do client scripts run?
Practise this on your own free instance.