- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:39 AM
This is for a map page. I want to show active incidents report and incident reports that were closed no more than 120 ago. I've got it working using two sets of conditions, however, I'd like to combine them into one. Is there a way?
// Active Security Incidents
var gt = new GlideRecord("u_incident_report");
gt.query('active', true);
gt.query();
while(gt.next()) {
var item = map.addItem(gt);
item.latitude = gt.u_latitude;
item.longitude = gt.u_longitude;
item.dialog_title = gt.getDisplayValue();
item.icon = "shop_icon.png";
item.icon_width = "16";
item.icon_height = "16";
}
// Closed Security Incidents not older than 120 days
var gr = new GlideRecord("u_incident_report");
gr.addQuery('closed_at', '>', gs.daysAgoStart(120));
gr.query();
while(gr.next()) {
var item = map.addItem(gr);
item.latitude = gr.u_latitude;
item.longitude = gr.u_longitude;
item.dialog_title = gr.getDisplayValue();
item.icon = "shop_icon.png";
item.icon_width = "16";
item.icon_height = "16";
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:42 AM
You can make use of the addOrCondition function. Here's how you'd do that:
gr.addQuery('active', true).addOrCondition('closed_at', '>', gs.daysAgoStart(120));
When using this function, it's important to keep in mind that this must be done to a query and not directly to the GlideRecord. That's why in my example above I called the function immediately after the addQuery function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:42 AM
You can make use of the addOrCondition function. Here's how you'd do that:
gr.addQuery('active', true).addOrCondition('closed_at', '>', gs.daysAgoStart(120));
When using this function, it's important to keep in mind that this must be done to a query and not directly to the GlideRecord. That's why in my example above I called the function immediately after the addQuery function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:51 AM
Thanks Adam, this seems to work perfectly. I don't fully understand your explanation if I'm honest. I noticed you changed the variable to gs. in your example: gs.addQuery('active', true).addOrCondition('closed_at', '>', gs.daysAgoStart(120)); whereas I was using gr and gt. Is this related to what you're talking about or just a typo?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:43 AM
var gt = new GlideRecord("u_incident_report");
gt.addEncodedQuery("active=true^NQclosed_at>=javascript:gs.daysAgoStart(120)");
gt.query();
while(gt.next()) {
var item = map.addItem(gt);
item.latitude = gt.u_latitude;
item.longitude = gt.u_longitude;
item.dialog_title = gt.getDisplayValue();
item.icon = "shop_icon.png";
item.icon_width = "16";
item.icon_height = "16";
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-26-2017 08:50 AM
This is how I'd seen it done previously but couldn't find an example to copy. Thanks