how to write onchange code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-22-2026 08:51 PM
If a user changes the caller in the incident form : Description should be the incident is
created by the user : caller full name , cmdb mandatory,state should be in progress.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2026 09:06 AM
Hi @NiharikaM859103,
Please refer to below code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2026 05:01 AM - edited ‎05-24-2026 05:44 AM
hey @NiharikaM859103
try this :
Table: Incident [incident]
Type: onChange
Field name: Caller
Script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue == '') {
return;
}
g_form.getReference('caller_id', function(caller) {
var callerName = caller.name;
g_form.setValue(
'description',
'Incident is created by the user : ' + callerName
);
g_form.setMandatory('cmdb_ci', true);
g_form.setValue('state', '2'); // In Progress
});
}*********************************************************************************************************
If this response helps, please mark it as Accept as Solution and Helpful.
Doing so helps others in the community and encourages me to keep contributing.
Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-27-2026 12:46 AM
hey @NiharikaM859103
Hope you are doing well.
Did my previous reply answer your question?
If it was helpful, please mark it as correct ✓ and close the thread . This will help other readers find the solution more easily.
Thankyou & Regards
Vaishali Singh
Servicenow Developer
Linkedin - https://www.linkedin.com/in/vaishali-singh-2273361bb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-24-2026 05:41 AM
Try this:
- Table: Incident [incident]
- Type: onChange
- Field name: Caller [caller_id]
- Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
g_form.getReference('caller_id', function(callerRecord) {
if (callerRecord) {
var descriptionText = 'The incident is created by the user: ' + callerRecord.name;
g_form.setValue('description', descriptionText);
g_form.setValue('state', '2');
g_form.setMandatory('cmdb_ci', true);
}
});
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti