Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to print(or show info msg) an array using getXMLAnswer method through client script?

KM SN
Tera Expert

I just want to send two details of caller to an array and bringing them back to client script and there using Client script i need to show the array whenever the caller field changes. but i am getting msg as below and i am adding script too.

ManiHouse1_0-1715323490467.png

 



Client Script:

var cid = g_form.getValue('caller_id');
var ga = new GlideAjax('gettingcallerdetails');
ga.addParam('sysparm_name','callerdetails');
ga.addParam('sysparm_caller', cid);
ga.getXMLAnswer(details);

function details(response){

        //var res = JSON.parse(response);
        var res = [response.toString()];
        g_form.addInfoMessage('Hi'+res);
        }
 
 
Script Include:


var gettingcallerdetails = Class.create();
gettingcallerdetails.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    callerdetails: function() {

        var abc = this.getParameter('sysparm_caller');
        //var obj = {};
        var obj = [];
        var utable = new GlideRecord('sys_user');
        if (utable.get(abc)) {

            //obj.phone = utable.getDisplayValue('mobile_phone');
            //obj.email = utable.getDisplayValue('email');
            obj.push(utable.getDisplayValue('mobile_phone'));
            obj.push(utable.getDisplayValue('email'));
            gs.addInfoMessage('SC :' + obj);
        }

        // return JSON.stringify(obj);

        return obj;


    },

    type: 'gettingcallerdetails'
});
6 REPLIES 6

Not applicable

Hi @KM SN ,

I'm able to solve your problem in my PDI please check below 

Client script : 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var cid = g_form.getValue('caller_id');
    var ga = new GlideAjax('gettingcallerdetails');
    ga.addParam('sysparm_name', 'callerdetails');
    ga.addParam('sysparm_caller', cid);
    ga.getXMLAnswer(details);

    function details(response) {
        var res = JSON.parse(response);
        g_form.addInfoMessage('Hi' + res);
    }


}

Script Include : 

callerdetails: function() {
        var abc = this.getParameter('sysparm_caller');
        //var obj = {};
        var obj = [];
        var utable = new GlideRecord('sys_user');
        if (utable.get(abc)) {
			var mobile = utable.getDisplayValue('mobile_phone')+"";
			var email = utable.getDisplayValue('email')+"";
            obj.push(mobile);
            obj.push(email);
            gs.addInfoMessage('SC :' + obj);
        }
        return JSON.stringify(obj);
    },

 

Result 

SarthakKashyap_0-1715326587155.png

 

Please mark my answer correct and helpful if this work's for you

Thanks and Regards 

Sarthak

 

Not applicable

@KM SN ,

Please mark my answer correct if this works for you😀

 

Thanks and Regards 

Sarthak