GlideRecord in Service Portal is not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 05:48 AM
Hello All,
I'm trying to perform Glide Record on a table by passing the Sys Id of a reference field to a function. The below code is perfectly working from administering view of the catalog Items(Maintain Items), but failing while tested from the Portal Page. Could any let me know what is wrong with the code with respect to Service Portal?
Below is the code onchange of a variable in catalog Item:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
//Type appropriate comment here, and begin script below
var blockname = g_form.getValue('Vacation'); //captures Sys Id of the Reference field from the variable of the Catalog item and passes it to the function func
func(blockname);
function func(blockname){
var Diggingin1 = new GlideRecord('u_vacation_details');
Diggingin1.addQuery('sys_id', blockname);
Diggingin1.query();
if (Diggingin1.next()){
blockname = Diggingin1.u_parent; //assign Sys Id of the Object to the variable blockname
}
if(blockname == ''){ //If the Sys Id of the Object is NULL, then set flite_approvall field(variable) with another column of object in the variable of Catalog Item.
g_form.setValue('variables.flite_approvall', Diggingin1.u_name_of_vacation);
}
else{ //If the Object has Sys Id, then recall(recursive) the function func with parameter blockname as the Sys Id of the Glided Object.
func(blockname);
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 06:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2017 06:17 AM
Hi Chuck,
UI Type is already set to ALL.
What I have observed in the Portal is, after Gliding the table, control is directly going to the Else statement(came to know by providing alert before and after Else actions in the code).
Not sure why it is going directly to the Else statement, eventhough a record exists with that Sys Id.
I have also checked the code by running in Background script, that's working fine there.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-04-2017 12:22 PM
It doesn't look like you have a callback function in your GlideRecord code. Service Portal won't return anything without the callback function. See this post for an example: Catalog Client Script on Service Portal is not working
If you look at the console log there should be a warning saying the GlideRecord needs a callback.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2017 05:50 AM
Hello,
Have you used a GlideAjax() or Script Include before? I have found that using an asynchronous GlideAjax works very well with the Service Portal and I use it in place of all GlideRecords when scripting for the portal.
Just like the link that Ann Costello shared.....here is where the asynchronous GlideAjax is described in ServiceNow Docs:
- Mel