On change client script error

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:15 PM
Hi All,
We are getting an error on state field 'onChange script error: TypeError: Cannot read properties of null (reading 'up') function onChange_change_request_state_14(control, oldValue, newValue, isLoading, isTemplate) { if (isLoading || newValue === '') { return; } if (newValue != "-5" || newValue != "-4") { $("impact_annotation").up().hide(); } else { $("impact_annotation").up().show(); } }'.
Below is the on change client script
Can anyone please help me on how to get rid of that error. Thanks in advance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:30 PM
Hi @Community Alums ,
If you are trying to hide and show field based on condition match then you can use g_form.setDisplay('impact_annotation', false); and g_form.setDisplay('impact_annotation', true); instead of $("impact_annotation").up().hide();.
Error state that "up" is not readable.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:33 PM
Hi @Community Alums ,
Looks like there are slight changes required in your script,
1)New value can't be both "-5" and "-4" simultaneously. We should use and instead.
2) Check weather $ function is working as expected or not if not replace with document.getElementById.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue != "-5" && newValue != "-4") {
$("impact_annotation").up().hide();
} else {
$("impact_annotation").up().show();
}
}
function showImpactAnnotation(bs) {
if (bs.next()) {
const isCritical = bs.busines_criticality == '1 - most critical' ||
bs.busines_criticality == '2 - somewhat critical';
$("my_annotation").up().setVisible(isCritical);
} else {
$("my_annotation").up().hide();
}
}
Thanks,
Pradeep
Regards,
Pradeep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2024 11:39 PM
Hi @Community Alums ,
Also you can use like below.
-------------------------------------------------------------------------
If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.
Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP
-------------------------------------------------------------------------

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2024 12:09 AM
Hi Runjay, I have modified the code as below and annotation should display only in new and assess state but it is displaying in all states.