- 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-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 10:26 AM
Thanks Mike! The GlideAjax worked with populating the variable.
I do have another question. In an 'onSubmit' catalog client script, I need to update a record in another table. So, GlideRecord only works on Desktop UI not Service Portal UI. Would I be able to utilize GlideAjax for that? If so, how? Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 10:45 AM
Yes, you can.
Can you share your script so I can help you with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2018 10:50 AM
Here's my script. I really appreciate you looking into this.
function onSubmit() {
var projName = g_form.getReference('project_name', callback);
function callback(projName)
{
var used = projName.u_used;
var ga = new GlideAjax('ConfidentialProject');
ga.addParam('sysparm_name', 'getProjectName');
if (used == 'true'){
ga.getXML(projectNameUsed);
}
if (used == 'false'){
ga.getXML(projectNameUnused);
}
}
function projectNameUsed(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('project_name', answer);
g_form.setReadOnly('project_name', true);
}
function projectNameUnused(response2){
var answer2 = response2.responseXML.documentElement.getAttribute("answer");
var proj = new GlideRecord('u_project_name');
proj.addQuery('sys_id', answer2);
proj.query();
if (proj.next()){
proj.u_used = 'true';
proj.update();
}
}
}