Help me with Script include , it's returning null

Vijay Kummamuru
Tera Contributor

client script 

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var user = g_form.getValue('requested_by');
alert(user);
var ga = new GlideAjax('paccount');
ga.addParam('sysparm_name','getAccount');
ga.addParam('sysparm_user', user);
ga.getXML(classdemo);

function classdemo(response) {

var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
g_form.setValue('project_account', answer);
}

 

//Type appropriate comment here, and begin script below

}

 

script include 

 

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

getAccount: function() {
var value = this.getParameter("sysparm_user");
gs.info("PA" + sysid);
var accountname = "";
var gr = new GlideRecord('x_800355_corpora_0_employee');
gs.info("Hello" + gr);
gr.addQuery('sys_id', value);
gr.query();
if (gr.next()) {
gs.log("hello" + gr.project_account);
accountname = gr.getValue(project_account);
}
return accountname;
//return accountname.getDisplayValue();
},

type: 'paccount'
});

9 REPLIES 9

Jitendra Diwak1
Kilo Sage

Hi @Vijay Kummamuru,

 

Correct this below code

 

if (gr.next()) {
gs.log("hello" + gr.project_account);
//accountname = gr.getValue(project_account);

accountname = gr.getValue('project_account'); //You have to put the value in quotes
}

 

Please try this above code.

 

Please accept my solution if it works for you and thumps up.

 

Thanks

Jitendra

Please accept my solution if it works for and thumps up.

@Jitendra Diwak1 @Community Alums  still getting Null 

 

Community Alums
Not applicable

Hi @Vijay Kummamuru ,

I tried your same script to incident table and it works for me please take reference from below script 

var accountname = "";
var gr = new GlideRecord('incident');
gr.addQuery('sys_id', '46e482d9a9fe198101d3e3f3e2a14459');
gr.query();
if (gr.next()) {
    gs.log("hello" + gr.number);
    accountname = gr.getValue('number');
    gs.log("accountname = " + accountname);
}

Result 

SarthakKashyap_0-1718278797488.png

Please mark my answer correct and helpful if this works for you

Thanks and Regards 

Sarthak

 

Hi @Vijay Kummamuru,

 

What you get in this log

gs.log("hello" + gr.project_account);

 

Thanks 

Jitendra 

Please accept my solution if it works for and thumps up.