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

Hi @Vijay Kummamuru,

 

Please validate that you are calling exact backend name project_account. And also validate you are getting sys in of user in client side and try to get other field value.

 

Thanks

Jitendra

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

Community Alums
Not applicable

Hi @Vijay Kummamuru ,

I checked your script there is one small error please use below script 

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"); // Please add string in project_account
}

 

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

Thanks and Regards 

Sarthak

Vijay Kummamuru
Tera Contributor

@Community Alums  even i was able to pull value in background script ,  not sure why it is not working here @Jitendra Diwak1  even logs are not coming 

 

Please find below screen shots and guide me

 

VijayKummamuru_0-1718284329533.pngVijayKummamuru_1-1718284362092.pngVijayKummamuru_2-1718284570404.pngVijayKummamuru_3-1718284599468.png

 

 

 

 

Hi @Vijay Kummamuru  The script include is failing at line 6  at gs.info("PA"+sysid ) as you kept sysid (which is not defined in code ) .

 

Please remove line 6 info log (or) instead of using sysid use value and test the code . you will recieve all logs and code will work.

 

Hi @Vijay Kummamuru ,

Here I am providing script to Auto Populate Callers Manager on Incident Form , you may follow the script to achieve your requirement.

Attaching screenshots for reference.

 

1.Client Script

client_script_autopopulate_manager.PNG

 

2.Script Include

script_include_autopopulte_manager.PNG

 

3.Output on Incident form.

incident_screenshot.PNG

 

 

Please mark my response as correct and helpful if it helped solved your question.

 

Thanks,

Rohit Suryawanshi