My code just doesnt work in PDI instance

Deeplaxmi
Tera Contributor

Hi,

 

I have just started using my PDI instance. I am new to it. I have been learning from Youtube past 2 days.

While coding in PDI, even though I checked my code many times, its correct but still there is no results. Even gs.log doesn't work.

Is there any PDI setting that I must do?

I tried 2 coding stories both just doesn't show any  results

 

What I did is created 3 fields in incident table as shown in screenshot. Requirement : Once "caller" is entered, then caller manager, caller mail and caller location should populate. I used below script include and client script but just nothing shows. Is there any PDI setting that i need to do on request of a new PDi?

 

 

Script include : 

var Hope = Class.create();
Hope.prototype = Object.extendsObject(AbstractAjaxProcessor, {
 
Autopopu: function(){
var gr = this.getParameter('sysparm_value');
 
gs.log("came");
var a = new GlideRecord('sys_user');
a.addQuery('sys_id',gr);
a.query();
if(a.next()){
gs.log("details"+a.u_caller_location+','+a.u_caller_manager+','+a.u_caller_email);
return a.u_caller_location+','+a.u_caller_manager+','+a.u_caller_email;
}
},
 
    type: 'Hope'
});
 
 
 
Client script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
 
   
var getcaller = g_form.getValue('caller_id');//check the quotes
//gs.log('visited');
var gazax = new GlideAjax('Hope');
gazax.addParam('sysparm_name','Autopopu');
gazax.addParam('sysparm_value',getcaller);
gazax.getXML('Automa');
 
function Automa(response){
 
 
var ans = response.responseXML.documentElement.getAttribute('ans');
 
var test = ans.split(',');
g_form.setValue('u_caller_location',test[2]);
g_form.setValue('u_caller_manager',test[1]);
g_form.setValue('u_caller_email',test[0]);
 
 
 
}
 
 
   
}

 

 

 

Script include

2 ACCEPTED SOLUTIONS

shubhamdubey
Mega Sage
Hi Youtube Family, I am Ravi Gaurav. I am Expert in ServiceNow . Welcome to my youtube channel. If you guys enjoyed it, make sure to Like👍 , Comment💬 and Subscribe❤️ _________________________________________ Copyright Disclaimer : All Rights to VideoLabel Co. & No Copyright infringement intende...

Abhishek M
Kilo Guru

Hi @Deeplaxmi,

 

I saw in your client script you have used the string when calling the callback function, you need to pass callback function name directly, also when getting an answer to get value returned from script include you need to use "answer" instead of "ans" that is a syntax please try below in client script and check.. also i have placed an alert on ans  variable so that you will be able to what answer is returning

 

Client script :

 

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


    var getcaller = g_form.getValue('caller_id'); //check the quotes
    //gs.log('visited');
    var gazax = new GlideAjax('Hope');
    gazax.addParam('sysparm_name', 'Autopopu');
    gazax.addParam('sysparm_value', getcaller);
    gazax.getXML(Automa);

    function Automa(response) {


        var ans = response.responseXML.documentElement.getAttribute('answer');

        var test = ans.split(',');
		alert(ans);
        g_form.setValue('u_caller_location', test[2]);
        g_form.setValue('u_caller_manager', test[1]);
        g_form.setValue('u_caller_email', test[0]);



    }
}

 

Mark helpful if worked 🙂

View solution in original post

7 REPLIES 7

Yes, i had changed those names. Gav ethe names that were in sys_user table. 

Thanks a lot for your help !!!!

Abhishek M
Kilo Guru

Hi @Deeplaxmi,

 

I saw in your client script you have used the string when calling the callback function, you need to pass callback function name directly, also when getting an answer to get value returned from script include you need to use "answer" instead of "ans" that is a syntax please try below in client script and check.. also i have placed an alert on ans  variable so that you will be able to what answer is returning

 

Client script :

 

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


    var getcaller = g_form.getValue('caller_id'); //check the quotes
    //gs.log('visited');
    var gazax = new GlideAjax('Hope');
    gazax.addParam('sysparm_name', 'Autopopu');
    gazax.addParam('sysparm_value', getcaller);
    gazax.getXML(Automa);

    function Automa(response) {


        var ans = response.responseXML.documentElement.getAttribute('answer');

        var test = ans.split(',');
		alert(ans);
        g_form.setValue('u_caller_location', test[2]);
        g_form.setValue('u_caller_manager', test[1]);
        g_form.setValue('u_caller_email', test[0]);



    }
}

 

Mark helpful if worked 🙂

Yes, I passed callback function directly and also corrected the 'answer' syntax. New things learned !!

 

Thank you so much for your assistance !!