onChange Client Script - Incident Form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 12:20 AM
I am trying to fill a field on incident form based on change on configuration item using the code below. It is not working. Also when I checked, the data is from this table cmdb_ci_business_app since the category selected for the incident is business apps. Please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2023 05:24 AM
Hi Eric,
First off, always use a callback function with getReference:
You don't really need to wrap this in the if not empty block as the first if statement stops the script from running if the field changes to empty. GetReference will only return every field from the referenced table, cmdb_ci in this case. If the field that you're looking for is on a different table, you'll need to use a GlideAjax call to a Script Include to do a GlideRecord on the other table and return the field. If you're not familiar with how to do this, here is an excellent guide, which includes a bit more than you need with the ability to return more than one field, but it's good to know how to do that too and doesn't hurt to follow the same format while only returning one field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2023 05:07 AM
Hi @Eric S1,
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cmp = g_form.getReference('cmdb_ci', mycallback);
function mycallback(cmp) {
g_form.setValue('u_ado_project', cmp.x_adbad_app_cr_ado_project);
}
}
Please mark this answer as correct and helpful if it solves your issue.
Regards,
Siva Jyothi M.