- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:40 AM
Hello Community,
I just want to know, if I need to fetch only one record. What would be the best approach.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:44 AM
@a41022639 The best way to get a single record from database is using .get() method. Here is an example of it
var grIncident = new GlideRecord('incident');
var returnValue = grIncident.get('99ebb4156fa831005be8883e6b3ee4b9');
gs.info(returnValue); // logs true or false
gs.info(grIncident.number); // logs Incident Number
For more information please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/c_GlideRecordAPI#r_G...(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:46 AM
Hello @a41022639 ,
1.The more focused way to retrieve only one record is with the help setLimit(1) function in GlideRecord.
var Inc = new GlideRecord('incident');
inc.addQuery(); // add your condition here
inc.setLimit(1);
if(inc.next()){
gs.info("Incident number is " + inc.number);
}
2. You can go with the get() function in GlideRecord();
Please mark my answer as accepted solution and give thumbs up.
Regards,
Abhishek Thakur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:44 AM
@a41022639 The best way to get a single record from database is using .get() method. Here is an example of it
var grIncident = new GlideRecord('incident');
var returnValue = grIncident.get('99ebb4156fa831005be8883e6b3ee4b9');
gs.info(returnValue); // logs true or false
gs.info(grIncident.number); // logs Incident Number
For more information please refer to https://developer.servicenow.com/dev.do#!/reference/api/vancouver/server_legacy/c_GlideRecordAPI#r_G...(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:46 AM
Hello @a41022639 ,
1.The more focused way to retrieve only one record is with the help setLimit(1) function in GlideRecord.
var Inc = new GlideRecord('incident');
inc.addQuery(); // add your condition here
inc.setLimit(1);
if(inc.next()){
gs.info("Incident number is " + inc.number);
}
2. You can go with the get() function in GlideRecord();
Please mark my answer as accepted solution and give thumbs up.
Regards,
Abhishek Thakur
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:49 AM - edited 05-07-2024 04:52 AM
@a41022639
so I am just assuming you would use gliderecord and use "IF" and also use SetLimit(number)..
so that it will be restricted to only one record.
let me know if this works.