OnChange client script going in loop
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
I have onChange client script to call 2 fields using script include based on field "Region".
If I select "Region", then location1 and location2 populates correctly and then I save the form.
But if I select "Region", then both location value populate correctly but I didn't save the form, and then select different "Region" again. value of region,location1 and location2 keeps changes/shuffle between selected values. It's going in loop. below is my script
...................................
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
Hi @Hafsa1
Can you share your script include. is the location 1 and location 2 getting fetched from 2 different table?
Why are you calling glideajax twice? Can it not be done by one call?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
an hour ago
@Hafsa1 The "looping" behavior you're seeing happens because GlideAjax is asynchronous.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
// Clear fields if Region is wiped
if (newValue === '') {
g_form.clearValue('u_location_1');
g_form.clearValue('u_location_2');
}
return;
}
// 1. Clear values immediately to prevent "shuffling" feedback
g_form.clearValue('u_location_1');
g_form.clearValue('u_location_2');
var region = newValue;
var gr = new GlideAjax('RegionHubUtils');
gr.addParam('sysparm_name', 'getArea1Hub');
gr.addParam('sysparm_location1', region);
gr.getXMLAnswer(function(answer) {
// Only set if the region hasn't changed again while waiting
if(g_form.getValue('u_region') == region) {
g_form.setValue('u_location_1', answer);
}
});
var gr1 = new GlideAjax('RegionHubUtils');
gr1.addParam('sysparm_name', 'getArea2Hub');
gr1.addParam('sysparm_location2', region);
gr1.getXMLAnswer(function(answer1) {
if(g_form.getValue('u_region') == region) {
g_form.setValue('u_location_2', answer1);
}
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
33m ago
@Nilesh Pol @Tanushree Maiti script include
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
8m ago
Hi @Hafsa1
Add this onChangeClient script in your sn_customerservice_location_hub table.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
g_form.setValue('location1', ''); //update your field name
g_form.setValue('location2', '');
return;
}
g_form.getReference('u_region', callBackMethod);
function callBackMethod(regionRecord) {
if (regionRecord) {
g_form.setValue('location1', regionRecord.u_location1);
g_form.setValue('location2', regionRecord.u_location2);
}
}
}
