0

Can anyone help me with how to call the script include from the client script?

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);
            }
        });
    }
}

enter image description here

Script Include: enter image description here

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;
},
TylerH
  • 20,799
  • 66
  • 75
  • 101
Mr world wide
  • 4,696
  • 7
  • 43
  • 97

1 Answers1

0

We need to use GlideAjax to call script include from client script.

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 video for Ref: https://youtu.be/zNGdVSCGggE

Mr world wide
  • 4,696
  • 7
  • 43
  • 97