how to write onchange code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
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
a month ago
Hi @NiharikaM859103,
Please refer to below code:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago - last edited a month ago
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
4 weeks ago
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
a month ago
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