- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 12:52 AM
I made an observation and thought it worth noting here in the community.
We use Agent Workspace in our organisation, alongside NextUI.
I have an onChange client script that looks for changes on field A, and sets the value of field B.
Another onChange client script looks for changes on field B and performs an action.
I found that in Agent workspace, the second client script does not trigger when filed B is updated by the first script.
The second script triggers fine if the trigger is manual form manipulation.
In nextUI, the second script is triggered by the first without issue.
I thought it worth noting the observation in here, to see if anyone else has experienced similar.
I worked around it by merging the required logic into the first client script.
Steps to replicate:
Create an onChange client script that looks for changes on a field (A) and uses g_form.setValue to set field B
Create an onChange client script that looks for changes on field B
Observe that (in Agent workspace) script 2 only triggers when field B is manually changed, not when script 1 runs
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 02:43 AM
if the 1st script is triggered via UI then 2nd should also trigger if it's onchange
Trigger for 1st script has to be from UI and then only it will work
Seems we are not able to get what you are trying to explain.
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
01-28-2025 12:57 AM
Are you sure the 2nd client script is configured to run on all views?
It should work provided the field is present on that view
Please share both the scripts screenshots.
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
01-28-2025 01:11 AM
I can confirm the field is present on both views and both scripts are set to UI Type All.
Script1:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue === '-5') {
g_form.setValue('hold_reason', 1);
}
}
Script2:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
if (newValue === '1' || newValue === '6') {
var now = new Date();
// Add 3 days (3 * 24 * 60 * 60 * 1000 milliseconds)
var threeDaysFromNow = new Date(now.getTime() + (3 * 24 * 60 * 60 * 1000));
// Format the date as 'DD/MM/YYYY HH:mm'
var day = String(threeDaysFromNow.getDate()).padStart(2, '0');
var month = String(threeDaysFromNow.getMonth() + 1).padStart(2, '0');
var year = threeDaysFromNow.getFullYear();
var hours = String(threeDaysFromNow.getHours()).padStart(2, '0');
var minutes = String(threeDaysFromNow.getMinutes()).padStart(2, '0');
var formattedDate = `${day}/${month}/${year} ${hours}:${minutes}`;
g_form.setValue('u_on_hold_timer', formattedDate);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-28-2025 01:17 AM
Are you saying the 2nd script works fine in native + configurable workspace but not working in legacy/older Agent workspace?
in your 2nd script don't use Date javascript class
Simply give alert and it should work.
Seems the native javascript Data class is giving some error in Agent workspace but works fine in Configurable workspace and native
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
01-28-2025 01:22 AM
Thanks for the response.
Yes, the 2nd script triggers and runs fine in native, but does not trigger at all in Agent Workspace.
I tried simply setting value in the second script using a string, removing all the date class bits.
This still resulted in the second script not triggering in workspace.
If I manually interact with the form field by clicking and changing it, this DOES trigger script 2.
This is why I landed on the conclusion that it does not trigger when field value is set programmatically.