Script IncludeのGlideAjaxが動作しない。

慶吾岡
Tera Expert

クライアントスクリプトでGlideAjaxを用いてスクリプトインクルードを呼び出したいのですが、うまく動作しません。ログも表示されないです。どうすれば正常に動作するでしょうか。

 

 

//Client Script
function onLoad() {
    //Type appropriate comment here, and begin script below
    g_form.addInfoMessage('text');
    var case_sysid = g_form.getValue('u_case');
    var ga = new GlideAjax('global.cscRelatedcaseinformationoutput');
    ga.addParam('sysparm_name', 'serverFunc');
    ga.addParam('case_sysid', case_sysid);
    g_form.addInfoMessage(case_sysid);
    ga.getXML(callback);

    function callback(response) { // Script Includeの処理結果がresponseに渡される
        var answer = response.responseXML.documentElement.getAttribute("answer"); // XML構造の中から結果を取り出す
        g_form.addInfoMessage('callback ' + answer);
        g_form.setValue('caller_id', case_contact);
    }
}
//Script Include
var cscRelatedcaseinformationoutput = Class.create();
cscRelatedcaseinformationoutput.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    initialize: function() {},
    serverFunc: function() {
        gs.info('AX');
        var case_sysid = this.getParameter('case_sysid');
        gs.info('case_sysid ' + case_sysid);
        var gr = new GlideRecord('sn_customerservice_case');
        gr.addQuery('sys_id', case_sysid);
        gr.query();
        gs.info('query ' + gr.getRowCount());
        while (gr.next) {
            gs.info('case_contact ' + case_contact);
            var case_contact = gr.getValue('contact');
            return case_contact;
        }
    },
    type: 'cscRelatedcaseinformationoutput'
});

 

スクリーンショット 2024-12-06 161215.pngスクリーンショット 2024-12-06 161227.png

3 ACCEPTED SOLUTIONS

jusfory1
Tera Expert

Do not overwritte its method initialize as extending AbstractAjaxProcessor, remove it from your code.

View solution in original post

Brad Bowman
Kilo Patron
Kilo Patron

You are missing the parenthesis in the next method call that could prevent this script from executing

        while (gr.next()) {

I don't think this matters, but Client callable / Glide AJAX enabled Script Includes do not have/need an initialize function.  Beyond this, are you getting the two infoMessages on the incident, with the correct case sys_id?

View solution in original post

具体的にはどの部分を削除すればいいですか?

View solution in original post

4 REPLIES 4

jusfory1
Tera Expert

Do not overwritte its method initialize as extending AbstractAjaxProcessor, remove it from your code.

具体的にはどの部分を削除すればいいですか?

Brad Bowman
Kilo Patron
Kilo Patron

You are missing the parenthesis in the next method call that could prevent this script from executing

        while (gr.next()) {

I don't think this matters, but Client callable / Glide AJAX enabled Script Includes do not have/need an initialize function.  Beyond this, are you getting the two infoMessages on the incident, with the correct case sys_id?

慶吾岡
Tera Expert

スクリプトを一部修正しましたが、問題は解決していません。

//Client Script
function onLoad() {
    //Type appropriate comment here, and begin script below
    g_form.addInfoMessage('text');
    var case_sysid = g_form.getValue('u_case');
    var ga = new GlideAjax('global.cscRelatedcaseinformationoutput');
    ga.addParam('sysparm_name', 'serverFunc');
    ga.addParam('case_sysid', case_sysid);
    g_form.addInfoMessage(case_sysid);
    ga.getXML(callback);

    function callback(response) { // Script Includeの処理結果がresponseに渡される
        var answer = response.responseXML.documentElement.getAttribute("answer"); // XML構造の中から結果を取り出す
        g_form.addInfoMessage('callback ' + answer);
        g_form.setValue('caller_id', answer);
    }
}