- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 12:33 PM
How can I run a Glide query from in a widget? (Service Portal)
This code runs fine in the script-background editor, but it doesn't work in the Server-script section of my widget:
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232"); // hardcoded good sample
destination_sys_id = grTask.sys_id;
When I run the code in Scripts, I get:
*** Script: sys_id: 0f4d...905
When I run it in the widget, I get:
{}
To elaborate on my Widget code:
data.test={ {data.test} }
(function(){
var destination_sys_id = "initialized";
var grTask = new GlideRecord('task');
grTask.get('number', "REQ0323232");
destination_sys_id = grTask.sys_id;
data.test = destination_sys_id;
})()
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 01:29 PM
instead of
destination_sys_id = grTask.sys_id;
try this:
destination_sys_id = grTask.sys_id.toString();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 12:58 PM
You should be able to do access GlideRecord from your service portal widget. When you say it doesn't work, what you do mean? It looks like you're assigned the sys_id of that record to an already declared server side JS variable. What are you doing with that variable that makes you think it doesn't work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2019 01:29 PM
instead of
destination_sys_id = grTask.sys_id;
try this:
destination_sys_id = grTask.sys_id.toString();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-05-2019 05:32 AM
Generally, you want to use getters and setters when working with GlideRecord, so I would do grTask.getValue('sys_id') rather than grTask.sys_id.toString().