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

Catalog client script to populate reference variable not working in Service Portal

Maria DeLaCruz
Tera Guru

Hello,

I've created the following onLoad catalog client script to auto-populate a reference variable, and it works great on the Desktop UI, but not the Service Portal UI.  Is there something in this script that is not supported in the Service Portal?  I do have "All" selected for the UI type.

 

function onLoad() {
//Type appropriate comment here, and begin script below
var proj = [];
var gr = new GlideRecord('u_project_name');
gr.addQuery('u_used', false);
gr.query();
while(gr.next())
{
proj.push(gr.u_number.toString());
}

proj.sort(function(a, b){return a-b});
//gs.print(proj[0]);

var confidential = new GlideRecord('u_project_name');
confidential.addQuery('u_number', proj[0]);
confidential.query();

if(confidential.next())
g_form.setValue('project_name', confidential.sys_id);
}

 

Any assistance would be greatly appreciated!


Thanks,
Maria

1 ACCEPTED SOLUTION

Mike Patel
Tera Sage

Doing Glirerecord query is not recommended in client script. Use GlideAJAX instead and script include

View solution in original post

7 REPLIES 7

Can you also share ConfidentialProject script includes

Yes.  Here's the script include:

Name:  ConfidentialProject
Client callable: true


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

getProjectName: function() {

var confProject = "";
var proj = [];
var gr = new GlideRecord('u_project_name');
gr.addQuery('u_used', false);
gr.query();
while (gr.next()) {
proj.push(gr.u_number.toString());
}

proj.sort(function(a, b){
return a-b;
});


var conf = new GlideRecord('u_project_name');
conf.addQuery('u_number', proj[0]);
conf.query();
if(conf.next()){
confProject = conf.sys_id;
}

return confProject;

},

});

sachin_namjoshi
Kilo Patron

Modify your code like below,

function onLoad() {
//Type appropriate comment here, and begin script below
var proj = [];
var gr = new GlideRecord('u_project_name');
gr.addQuery('u_used', false);
gr.query();
while(gr.next())
{
proj.push(gr.u_number.toString());
}

proj.sort(function(a, b){return a-b});
//gs.print(proj[0]);

var confidential = new GlideRecord('u_project_name');
confidential.addQuery('u_number', proj[0].toString());
confidential.query();

if(confidential.next())
g_form.setValue('project_name', confidential.sys_id);
}

Alsom Instead of gliderecord, it's recommended use glideajax in your client script.

 

Regards,

Sachin