
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 12:03 PM
Hi Experts,
In Service Portal, I am using the Data Table from Instance Definition widget to display the list of records.
I am able to see the filter. How can I use this filter to perform condition building?
Thanks,
Sanjiv
Please mark this response as correct or helpful if it assisted you with your question.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2017 01:31 PM
Thanks Jesse. I was able to make it work in Instance Definition, because ultimately both Data table from URL definition and Data tale from instance Definition embedding the same widget widget-data-table. I just needed to pass 'enable_filter' as true and it started working.
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2018 10:50 AM
Can you share screenshot of your widget server script?
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2018 11:01 AM
This is the server script for the custom cloned Data Table Instance
///////////
(function(){
/* "use strict"; - linter issues */
// populate the 'data' object
var sp_page = $sp.getValue('sp_page');
var pageGR = new GlideRecord('sp_page');
pageGR.get(sp_page);
data.page_id = pageGR.id.getDisplayValue();
$sp.getValues(data);
if (data.field_list) {
data.fields_array = data.field_list.split(',');
} else {
data.field_list = $sp.getListColumns(data.table);
}
if (input) {
data.p = input.p;
data.o = input.o;
data.d = input.d;
data.q = input.q;
}
data.p = data.p || 1;
data.o = data.o || $sp.getValue('order_by');
data.d = data.d || $sp.getValue('order_direction');
data.page_index = (data.p - 1);
data.window_size = $sp.getValue('maximum_entries') || 10;
data.window_start = (data.page_index * data.window_size);
data.window_end = (((data.page_index + 1) * data.window_size));
data.filter = $sp.getValue("filter");
copyParameters(data, ['p', 'o', 'd', 'filter']);
copyParameters(data, ['relationship_id', 'apply_to', 'apply_to_sys_id']);
function copyParameters(to, names) {
names.forEach(function(name) {
data[name] = $sp.getParameter(name);
})
}
var gr = new GlideRecordSecure(data.table);
if (!gr.isValid()) {
data.invalid_table = true;
data.table_label = options.title;
return;
}
data.table_label = options.title;
var widgetParams = {
table: data.table,
fields: data.field_list,
o: data.o,
d: data.d,
filter: data.filter,
filterACLs: true,
window_size: data.window_size,
view: 'sp',
title: options.title,
show_breadcrumbs: true,
enable_filter:true,
displayValue: true
};
data.dataTableWidget2 = $sp.getWidget('data_table_viewall', widgetParams);
})();
/////
and this is from the custom cloned data table widget, I had to make this so it can have a working 'view-all' button. This also makes the last part makes sense where it's calling view all
/////
(function() {
if (!input) // asynch load list
return;
data.msg = {};
data.msg.sortingByAsc = gs.getMessage("Sorting by ascending");
data.msg.sortingByDesc = gs.getMessage("Sorting by descending");
data.title = options.title || input.title;
/*
* data.table = the table
* data.p = the current page starting at 1
* data.o = the order by column
* data.d = the order by direction
* data.keywords = the keyword search term
* data.list = the table data as an array
* data.invalid_table = true if table is invalid or if data was not succesfully fetched
* data.table_label = the table's display name. e.g. Incident
* data.table_plural = the table's plural display name. e.g. Incidents
* data.fields = a comma delimited list of field names to show in the data table
* data.column_labels = a map of field name -> display name
* data.window_size = the number of rows to show
* data.filter = the encoded query
*/
// copy to data[name] from input[name] || option[name]
optCopy(['table', 'p', 'o', 'd', 'filter', 'filterACLs', 'fields', 'keywords', 'view']);
optCopy(['relationship_id', 'apply_to', 'apply_to_sys_id', 'window_size']);
if (!data.table) {
data.invalid_table = true;
data.table_label = "";
return;
}
if (!data.fields) {
if (data.view)
data.fields = $sp.getListColumns(data.table, data.view);
else
data.fields = $sp.getListColumns(data.table);
}
data.view = data.view || 'mobile';
data.table = data.table || $sp.getValue('table');
data.filter = data.filter || $sp.getValue('filter');
data.keywords = data.keywords || $sp.getValue('keywords');
data.p = data.p || $sp.getValue('p') || 1;
data.p = parseInt(data.p);
data.o = data.o || $sp.getValue('o') || $sp.getValue('order_by');
data.d = data.d || $sp.getValue('d') || $sp.getValue('order_direction');
data.page_index = data.p - 1;
data.show_new = data.show_new || options.show_new;
var windowSize = data.window_size || $sp.getValue('maximum_entries') || 20;
windowSize = parseInt(windowSize);
if (isNaN(windowSize) || windowSize < 1)
windowSize = 20;
data.window_size = windowSize;
var gr;
if (gs.getProperty("glide.security.ui.filter") == "true" || GlideTableDescriptor.get(data.table).getED().hasAttribute("glide.security.ui.filter")) {
gr = new FilteredGlideRecord(data.table);
gr.applyRowSecurity();
} else
gr = new GlideRecordSecure(data.table);
if (!gr.isValid()) {
data.invalid_table = true;
data.table_label = options.title;
return;
}
data.canCreate = gr.canCreate();
data.newButtonUnsupported = data.table == "sys_attachment";
data.table_label = data.title;
data.table_plural = data.title;
if (data.filter) {
if (data.filterACLs)
gr = $sp.addQueryString(gr, data.filter);
else
gr.addEncodedQuery(data.filter);
}
if (data.keywords){
gr.addQuery('123TEXTQUERY321', data.keywords);
data.keywords = null;
}
data.filter = gr.getEncodedQuery();
if (data.relationship_id) {
var rel = GlideRelationship.get(data.relationship_id);
var target = new GlideRecord(data.table);
var applyTo = new GlideRecord(data.apply_to);
applyTo.get("sys_id", data.apply_to_sys_id);
rel.queryWith(applyTo, target); // put the relationship query into target
gr.addEncodedQuery(target.getEncodedQuery()); // get the query the relationship made for us
}
if (data.o){
if (data.d == "asc")
gr.orderBy(data.o);
else
gr.orderByDesc(data.o);
}
data.window_start = data.page_index * data.window_size;
data.window_end = (data.page_index + 1) * data.window_size;
gr.chooseWindow(data.window_start, data.window_end);
gr._query();
data.row_count = gr.getRowCount();
data.num_pages = Math.ceil(data.row_count / data.window_size);
data.column_labels = {};
data.fields_array = data.fields.split(',');
// use GlideRecord to get field labels vs. GlideRecordSecure
var grForLabels = new GlideRecord(data.table);
for (var i in data.fields_array) {
var field = data.fields_array[i];
var ge = grForLabels.getElement(field);
if (ge == null)
continue;
data.column_labels[field] = ge.getLabel();
}
data.list = [];
while (gr._next()) {
var record = {};
$sp.getRecordElements(record, gr, data.fields);
if (gr instanceof FilteredGlideRecord) {
// FilteredGlideRecord doesn't do field-level
// security, so take care of that here
for (var f in data.fields_array) {
var fld = data.fields_array[f];
if (!gr.isValidField(fld))
continue;
if (!gr[fld].canRead()) {
record[fld].value = null;
record[fld].display_value = null;
}
}
}
record.sys_id = gr.getValue('sys_id');
data.list.push(record);
}
data.enable_filter = (input.enable_filter == true || input.enable_filter == "true" ||
options.enable_filter == true || options.enable_filter == "true");
var breadcrumbWidgetParams = {
table: data.table,
query: data.filter,
enable_filter: true,
show_breadcrumbs: true
};
data.filterBreadcrumbs = $sp.getWidget('widget-filter-breadcrumbs', breadcrumbWidgetParams);
// copy to data from input or options
function optCopy(names) {
names.forEach(function(name) {
data[name] = input[name] || options[name];
})
}
})();
/////

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2018 11:37 AM
In your view all widget, in HTML, there is below line. Can you remove the ng-if part from here (ng-if="options.show_breadcrumbs && (data.filter || data.enable_filter)")?
<div ng-if="options.show_breadcrumbs && (data.filter || data.enable_filter)" class="filter-breadcrumbs">
<sp-widget widget="data.filterBreadcrumbs"></sp-widget>
</div>
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2018 11:43 AM
If I delete just the div part with ng-if it doesn't change anything and if I delete all 3 the filter goes away all together

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-20-2018 12:00 PM
So you see the filter already. Can you share a screenshot of where the problem is?
Please mark this response as correct or helpful if it assisted you with your question.