i have written 2 client scrpits
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
1 st client script is onload test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @17911a03e8
There could be several reasons for the conflict:
Both client scripts have the same execution order.
The second client script uses the scratchpad, which triggers a Display Business Rule to run before the onLoad client scripts execute.
Best practice: Consolidate the logic into a single onLoad client script. Having multiple onLoad scripts can increase processing time and negatively impact the user experience.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Dot walk on user field and check if it is VIP user as your client script 2 is not checking correctly.
Where possible, merge client scripts and do not have multiple client scripts for same condition [in your case onLoad]
Follow below best practices
If my response helped to guide you or answer your query, please mark it helpful & accept the solution.
Thanks,
Bhuvan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @17911a03e8 ,
Check your scratchpad variable returning any value if value not defined it will not execute.
if (g_scratchpad.yourVariableName !== undefined) {
// The scratchpad variable is defined.
} else {
// The scratchpad variable is undefined.
}
If my response helped, please mark it as the accepted solution ✅ and give a thumbs up👍.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @17911a03e8
Both your client scripts use function onLoad().
In JavaScript, if two functions have the same name, the last one loaded overwrites the first. That’s why only one script executes.
Why disabling works: With only one active, there’s no overwrite, so it runs fine.
Fix:
- Don’t reuse the same function name.
- Either give them unique names (onLoadAdminCheck, onLoadVIPCheck), or just keep the ServiceNow default onLoad(control, oldValue, newValue, isLoading, isTemplate) signature.
- That way, ServiceNow will load and run each script independently.