- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 10:43 PM
Hi All,
Kindly help me on my concern,
if we have multiple OnChange client scripts on single field on same table , there Reducing all client scripts into single OnChange is Good Idea ?
if reducing is Good Idea , then why ServiceNow OOB has multiple scripts on single field on same table ? , they should have designed in Single -OnChange script . why they didn't design in single OnChange script ?
Please share your opinions and suggestions on this.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 10:49 PM
yes it's recommended but sometimes each onChange is written to handle different use-case.
But if the script becomes too complex with multiple IF else then better to separate those out.
Developers might have created new onChange on state field without noticing there was already onChange.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 10:51 PM - edited 07-27-2025 10:54 PM
Hi @Sironi ,
Although there are multiple client scripts on same field but there requirements and codes are different. You can't put all conditions/requirement in one client script. It will be very messy to understand and very difficult to maintain code so code is always broken down into pieces (one requirement, one code) for better readability, maintenance.
I dont think clubbing multiple codes/requirements in one scrip tis possible and advisable.
If my answer helped you in anyways, please mark it solution accepted.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 11:10 PM
If you do everything with one client script, it will be very complex to add another requirement to it, because every single use case that is handled through that client script, will have to be tested again.
It will be difficult to troubleshoot and when you are making Ajax calls it becomes impossible to follow.
Breaking it down helps with making it understandable (the title of the client script already tells you what it does) and it is easily changed.
That being said: if it is handling the same use case, it should be in the same script. My experience is that often things are added instead of updated. Many 'developers' just add something to comply to certain requirements instead of checking what's already there.
So you could probably combine some of those scripts, but make sure it stays easy to troubleshoot/read and also maintainable.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2025 06:02 AM
Hi @Sironi ,
If we got such reuqirements which can't be clubbed together so definitely we need to create separate scripts, we dont have any choice. It will not result in any performance issue. Even if it willdo we have any other choice, no then go ahed. Only thing we can keep in mind to follow best practices while writing our code/scripts.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 10:49 PM
yes it's recommended but sometimes each onChange is written to handle different use-case.
But if the script becomes too complex with multiple IF else then better to separate those out.
Developers might have created new onChange on state field without noticing there was already onChange.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 06:57 AM
Thanks for your reply and sharing your opinion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-28-2025 07:00 AM
Glad to help.
Please close the thread by marking appropriate responses as correct so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2025 10:51 PM - edited 07-27-2025 10:54 PM
Hi @Sironi ,
Although there are multiple client scripts on same field but there requirements and codes are different. You can't put all conditions/requirement in one client script. It will be very messy to understand and very difficult to maintain code so code is always broken down into pieces (one requirement, one code) for better readability, maintenance.
I dont think clubbing multiple codes/requirements in one scrip tis possible and advisable.
If my answer helped you in anyways, please mark it solution accepted.
Regards,
Nikhil Bajaj
Regards,
Nikhil Bajaj