现在如何从客户端脚本服务调用脚本包含?

How to call script include from the client script servicenow?

任何人都可以帮助我如何从客户端脚本调用脚本包含吗?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {

    if (isLoading || newValue === '') {
        return;
    }

    //Current assignment group
    var assignment_group = newValue;
    if(assignment_group){
        var coe = '';
        var ga = new GlideAjax('sn_hr_core.scriptIncludeNameUtils'); //Script include
        ga.addParam('sysparm_name','MethodName'); //Method/Function
        ga.addParam('assignment_group',assignment_group); //Parameter
        ga.getXMLAnswer(function(response){
            coe = response;
            if(coe){
                g_form.setValue('u_hr_coe', coe);
            }
        });
    }
}

脚本包括:

MethodName: function (assignment_group) {
    var sys_id = this.getParameter('assignment_group') ? this.getParameter('assignment_group') : assignment_group; //Params
    var result = '';
    if(sys_id){
        var grSysChoice = new GlideRecord('sys_choice');
        grSysChoice.addEncodedQuery("element=assignment_group^name=sn_hr_core_case^dependent_value="+sys_id);
        grSysChoice.orderBy('sequence');
        grSysChoice.setLimit(1);
        grSysChoice.query();
        if(grSysChoice.next()) {
            result = grSysChoice.getValue('value');
        }
    }
    return result;
},

我们需要使用 GlideAjax 从客户端脚本中调用脚本 include。

var ga = new GlideAjax('sn_hr_core.scriptIncludeNameUtils'); //Script include
ga.addParam('sysparm_name','MethodName'); //Method/Function
ga.addParam('assignment_group',assignment_group); //Parameter
ga.getXMLAnswer(function(response){
    coe = response;
    if(coe){
        g_form.setValue('u_hr_coe', coe);
    }
});

供参考的 Youtube 视频: https://youtu.be/zNGdVSCGggE