- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 01:29 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 01:33 PM
Doing Glirerecord query is not recommended in client script. Use GlideAJAX instead and script include

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 12:13 PM
Can you also share ConfidentialProject script includes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2018 12:38 PM
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;
},
});

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2018 01:34 PM
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