logo

NJP

GlideQuery NOT GlideRecord

dhruvsn · Aug 24, 2020 · article

Hello guys,

Today I was going through some blogs from @jacebenson and I found a really interesting thing called “GlideQuery”. not GlideRecord

image

YAA!!!

I decided to explore this. There were no docs no session nothing. Literally nothing. I messaged Jace at discord to know more. I had a quick chat and started exploring. I found it really helpful as in it gives me the control which I always wanted to have while using GlideRecord. I mean it is just wrapper around GlideRecord but still.

I have recorded one video. Code that I showed in the video is below:

For Plugin Activation:

var plugins = [];
plugins.push('com.sn_glidequery');
var main = new GlideMultiPluginManagerWorker();
main.setPluginIds(plugins);
main.setProgressName("Plugin Installer");
main.setBackground(true);
main.start();

Sample 1:

var gd=new GlideQuery('sys_user')
.whereNull('last_name')
.select('first_name','email')
.forEach(function(user){
gs.print(user);
});

Sample 2:

var gd=new GlideQuery('sys_user')
.where('user_name',"STARTSWITH",'a')
.select('first_name','email')
.forEach(function(user){
gs.print(JSON.stringify(user));
});

Sample 3:

var gd = new GlideQuery('sys_user')
.getBy({
first_name: 'Fred',
last_name: 'Luddy'
}, ['first_name', 'last_name', 'city', 'active'])
.orElse({
first_name: 'Nobody',
last_name: 'Found',
city: 'Nowhere',
active: false
});
gs.print(JSON.stringify(gd));

Sample 4:

var gd = new GlideQuery('incident')
.limit(20)
.select('number')
.forEach(function(user){
gs.print(JSON.stringify(user));
});

Sample 5:

var user = new GlideQuery('sys_user')
.insertOrUpdate({
first_name: 'Debasis',
last_name: 'Majhi'
})
.orElse(null);

Links:

Jace Benson Article

In case you need any help, please do connect with me. It will be my pleasure to help you.

Happy Learning Guys!!!

—–>Dhruv Gupta

View original source

https://dhruvsn.wordpress.com/2020/08/24/glidequery-not-gliderecord/