- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 01:32 AM
Hi Team,
i am trying to hide/show choice values of status filed(state) based on status field only. but i am getting onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] } this error.
Please let me know how to solve this one.
below is my sample code.
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if (newValue == 1){
g_form.addOption('state', 7);
}
else {
if (newValue == 10 || newValue == 18 || newValue == 6 || newValue == 3){
g_form.removeOption('state', 7);
}
}
}
Thank you,
Hari Kishan.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:42 AM
you can run onload client script and run it only for existing records and not new one
function onLoad(){
if(!g_form.isNewRecord()){
var val = g_form.getValue('state');
if (val == 10 || val == 18 || val == 6 || val == 3){
g_form.removeOption('state', 7);
}
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 01:38 AM
Hi
to my mind, your code creates an endless loop as long as the call stack (part of the memory) exceeds the limit.
Please be aware of what is happening in your code: You change the form field, whereupon a new onChange event is triggered and then the code is executed again from the beginning.
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:30 AM
Hi Maik,
Thanks for the info. so, because of the endless Loop i am getting this error. is there any workaround to acheive my goal?
i.e, if state value is new, show cancelled choice in the choice list, if we select any other state value, hide the cancelled choice from the list.
if workaround is there, Please provide the sample script.
Thanks,
Hari Kishan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:39 AM
Hi
try the following extended version in the first part
if (isLoading || newValue === '' || newValue == oldValue) {
return;
}
Kind regards
Maik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 03:00 AM
Hi Maik,
it is working Partially, when i changing from new to open, cancelled is hiden. and when i changed from open to new, still cancelled is hidden. that should not happen.
Thanks,
Hari Kishan.