error: [onChange script error: RangeError: Maximum call stack size exceeded

jieLian123
Tera Expert

I write a string convert code.

but when I call it through form, I got an error below.

onChange script error: RangeError: Maximum call stack size exceeded function () { [native code] }

can anyone help me.

 

jieLian123_0-1705920690517.png

 

5 REPLIES 5

Amit Verma
Kilo Patron
Kilo Patron

Hi @jieLian123 

 

Your code might be creating an endless loop due to which the call stack (part of the memory) exceeds the limit. Please have a look on the below posts to troubleshoot. Also, debug your code to see where the loop is being created and fix it.

 

https://www.servicenow.com/community/developer-forum/how-to-fix-a-quot-rangeerror-maximum-call-stack...

https://www.servicenow.com/community/csm-forum/how-to-solve-onchange-script-error-rangeerror-maximum...

https://www.servicenow.com/community/developer-forum/onchange-script-error-rangeerror-maximum-call-s...

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Thanks.

I have move the toHalfWidth function to a script include using GlideAjax and called it in my onChange script.

it seems working well when I input something the first time.

but when I was tring to change it again to trigger the script.

I cannnot change it, I kept getting the converted value the first time script include returns to me.

 

jieLian123_0-1705980519706.png

 

Hi @jieLian123 

 

Can you please share your script include code as well ? Also, I can see 2 On-Change Client Scripts. Any particular reason for that ?

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

yeah,please refer to the script include code below.
and I have removed one onChange script.
I successfully turn a full width string 'アアアアアアア12345'
to a half width  'アアアアアアア12345' .
but when I was trying to change 'アアアアアアア12345' to something else, I just cannnot change it 
in the form.
 
var stringConvert = Class.create();
stringConvert.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
 
    stringConvertToHalfWidthHiragana: function(str) {
        var str1 = this.getParameter('sys_parm1'); // 引数"sys_parm1"を取得
        // 全角ひらがなを半角ひらがなに変換
str1 = str1.replace(/[A-Za-z0-9]/g, function(s) {
            return String.fromCharCode(s.charCodeAt(0) - 0xFEE0);
        });
        str1 = str1.replace(/[\u3041-\u3096]/g, function(s) {
            return String.fromCharCode(s.charCodeAt(0) + 0x60);
        });
 
        var kanaMap = {
            "ガ": "ガ",
            "ギ": "ギ",
            "グ": "グ",
            "ゲ": "ゲ",
            "ゴ": "ゴ",
            "ザ": "ザ",
            "ジ": "ジ",
            "ズ": "ズ",
            "ゼ": "ゼ",
            "ゾ": "ゾ",
            "ダ": "ダ",
            "ヂ": "ヂ",
            "ヅ": "ヅ",
            "デ": "デ",
            "ド": "ド",
            "バ": "バ",
            "ビ": "ビ",
            "ブ": "ブ",
            "ベ": "ベ",
            "ボ": "ボ",
            "パ": "パ",
            "ピ": "ピ",
            "プ": "プ",
            "ペ": "ペ",
            "ポ": "ポ",
            "ヴ": "ヴ",
            "ヷ": "ヷ",
            "ヺ": "ヺ",
            "ア": "ア",
            "イ": "イ",
            "ウ": "ウ",
            "エ": "エ",
            "オ": "オ",
            "カ": "カ",
            "キ": "キ",
            "ク": "ク",
            "ケ": "ケ",
            "コ": "コ",
            "サ": "サ",
            "シ": "シ",
            "ス": "ス",
            "セ": "セ",
            "ソ": "ソ",
            "タ": "タ",
            "チ": "チ",
            "ツ": "ツ",
            "テ": "テ",
            "ト": "ト",
            "ナ": "ナ",
            "ニ": "ニ",
            "ヌ": "ヌ",
            "ネ": "ネ",
            "ノ": "ノ",
            "ハ": "ハ",
            "ヒ": "ヒ",
            "フ": "フ",
            "ヘ": "ヘ",
            "ホ": "ホ",
            "マ": "マ",
            "ミ": "ミ",
            "ム": "ム",
            "メ": "メ",
            "モ": "モ",
            "ヤ": "ヤ",
            "ユ": "ユ",
            "ヨ": "ヨ",
            "ラ": "ラ",
            "リ": "リ",
            "ル": "ル",
            "レ": "レ",
            "ロ": "ロ",
            "ワ": "ワ",
            "ヲ": "ヲ",
            "ン": "ン",
            "ァ": "ァ",
            "ィ": "ィ",
            "ゥ": "ゥ",
            "ェ": "ェ",
            "ォ": "ォ",
            "ッ": "ッ",
            "ャ": "ャ",
            "ュ": "ュ",
            "ョ": "ョ",
            "。": "。",
            "、": "、",
            "ー": "ー",
            "「": "「",
            "」": "」",
            "・": "・"
        };
        var reg = new RegExp('(' + Object.keys(kanaMap).join('|') + ')', 'g');
        return str1
            .replace(reg, function(match) {
                return kanaMap[match];
            })
            .replace(/゛/g, '゙')
            .replace(/゜/g, '゚');
    },
 
    type: 'stringConvert'
});