AJAX call example 2: return single value

AJAX call example 2: return single value

Client script code:

//--author: RDS Feb 2018
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        // return;
    }
    var ga=new GlideAjax('fj_servicerequest_ajax');
    ga.addParam('sysparm_name', 'refreshItemDescription');
    ga.addParam('sysparm_req_type', newValue);
    ga.addParam('sysparm_req_category', g_form.getValue('fj_request_category'));
    ga.addParam('sysparm_req_subcategory',           g_form.getValue('fj_request_subcategory'));
     ga.getXMLAnswer(function(answer) {
         //alert('AJAX return:' + answer);
         g_form.setValue('fj_request_shortdescription',answer);
     });
    }
}

Script include script (client callable):

var my_ajax_funcs_sc = Class.create();
my_ajax_funcs_sc.prototype = Object.extendsObject(AbstractAjaxProcessor, {
   
    refreshItemDescription: function (){
        var sreturn='';
       
        var sDescr='';
        var sChrg='No';
        var grFJReq=new GlideRecord('u_fujitsu_request_types');
        grFJReq.addQuery('u_request_type', this.getParameter('sysparm_req_type'));
        grFJReq.addQuery('u_request_category', this.getParameter('sysparm_req_category'));
        grFJReq.addQuery('u_request_subcategory', this.getParameter('sysparm_req_subcategory'));
        grFJReq.query();
        if (grFJReq.next()){
            sreturn=grFJReq.u_request_short_description;
            
        }
        return (sreturn);
    },

    type: 'my_ajax_funcs_sc'
});

Comments

Popular posts from this blog

Running transform maps asynchronously

Post a command to the ECC queue for the mid server to initiate a powershell file copy

GlideRecord setValue