- 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 02:01 AM
there is extra } in the code.
Can you share full code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:19 AM
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);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:24 AM
Hi,
I agree with point mentioned by Maik.
It will go in loops.
What is your business requirement here?
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 02:35 AM
Hi Ankur,
my requirement is, show cancelled choice value in the choice list if state is new. for all other states hide the cancelled choice from the list.
by Default, when form opens (at creation of case) it will be in new state only.
Thanks,
Hari Kishan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā09-24-2021 02:41 AM
Hi,
try updating as this
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
if(oldValue != newValue){
if (newValue == 1){
g_form.addOption('state', 7);
}
else {
if (newValue == 10 || newValue == 18 || newValue == 6 || newValue == 3){
g_form.removeOption('state', 7);
}
}
}
}
Regards
Ankur
Ankur
⨠Certified Technical Architect || ⨠9x ServiceNow MVP || ⨠ServiceNow Community Leader