Data Table Widget
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2016 10:29 AM
Using the Data Table widget in the Service Portal that comes with Helsinki. Cloned it so that I could make it work for me. I added the table name (change_request) and added the fields I wanted to see. That however doesn't seem to be what that field means when I edit the widget. The widget defaults to 4 fields (Number,Category,Short Description and Approval). I did not select all of these and actually added a couple others I wanted to see but they don't show. I love the look of the table that it presents, but it's just not acting the way I expected. What am I missing about customizing/configuring a widget?
- Labels:
-
Performance Analytics
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 12:05 PM
Thanks Altamish.
Yes. I do agree this widget has so many bugs. It uses variables in the script that are not available for configuration.For instance, 'options.show_new'. This no where on the configuration page of widget and needs to be hard coded for the 'New' button to appear. I'm not sure if they did this on purpose.
Regards,
Darshak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 12:14 PM
Hi Darshak,
Omit new button and filter in list layout of Service Portal This is a similar thread.
The syntax that worked for me in the client side controller was:
$scope.options.show_new = true;
I agree though this Data Table widget could be more user friendly. Customizing it can be a real pain.
Best,
Phil E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 12:20 PM
Thanks Philip.
Do you think is there any way, the button can be displayed based on the user role? If I'm not mistaken setting options.show_new = true makes it a default case where every user can see the use button. I'm using data table from instance definition and need to modify the underlying data table widget.
Regards,
Rama
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-09-2016 12:34 PM
Hi Rama,
Yes it is possible and yes you are correct you need to be editing the underlying table widget being called by the instance definition. In your server side code you still have access to the gs.getUserID() and that returns the current user's sys_id and from there you will be able to pass a boolean value to your client controller. If that boolean is true then $scope.options.show_new = true; if that boolean is false then $scope.options.show_new = false;
I know there is a few more steps than what I just provided you, however with the knowledge that you still have access to GS methods on the portal and then appending the boolean to the c.data object and then passing that into the client should be enough for you to be on your way.
Hope that Helps!
Philip E.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2017 09:16 AM
Stanley, rather than hard-coding the fields for each of these tables, why not define a view for each table and set the options.view property accordingly for each of your widget instances? The $sp.getListColumns() function takes the view as a parameter and returns the fields defined in that view. I personally like to have more control over the data being pulled into my widgets, so I wrote the following function to replace $sp.getListColumns():
function getFields(table, view) {
view = view || 'default';
var fields = [];
var gr = new GlideRecord(table);
var grView = new GlideRecord('sys_ui_view');
var grList = new GlideRecord('sys_ui_list');
var grItem = new GlideRecord('sys_ui_list_element');
grView.addQuery('name', view);
grView.query();
if (grView.next()) {
grList.addQuery('name', table);
grList.addQuery('view', grView.sys_id);
grList.query();
if (grList.next()) {
grItem.addQuery('list_id', grList.sys_id);
grItem.orderBy('position');
grItem.query();
while (grItem.next()) {
var name = grItem.element;
var element = gr.getElement(name);
var descriptor = element.getED();
fields.push({
label: descriptor.getLabel(),
name: descriptor.getName(),
type: descriptor.getInternalType()
});
}
}
}
return fields;
}
This function will only work for list views (because it's pulling from the sys_ui_list table). If you want to get the fields defined in a form view, use the following function:
function getFields(table, view) {
view = view || 'default';
var fields = [];
var gr = new GlideRecord(table);
var grView = new GlideRecord('sys_ui_view');
var grSection = new GlideRecord('sys_ui_section');
var grItem = new GlideRecord('sys_ui_element');
grView.addQuery('name', view);
grView.query();
if (grView.next()) {
grSection.addQuery('name', table);
grSection.addQuery('view', grView.sys_id);
grSection.query();
if (grSection.next()) {
grItem.addQuery('sys_ui_section', grSection.sys_id);
grItem.orderBy('position');
grItem.query();
while (grItem.next()) {
var name = grItem.element;
var element = gr.getElement(name);
var descriptor = element.getED();
fields.push({
label: descriptor.getLabel(),
name: descriptor.getName(),
type: descriptor.getInternalType()
});
}
}
}
return fields;
}