- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:20 PM
Hi,
I'd like to know if there's an easy way to hide the "Data Table from Instance Definition" widget (or rather, instances of this widget) if no records are returned. The use case is the following: we have a custom table that's populated from a record producer, and we want to be able to show users a list of their records in this custom table on the portal, akin to "My Requests" - but only if it's relevant to them, aka if they have created entries in this custom table via the record producer. We want this to display on the "My Requests" page, as seperate widgets below the requests widget, but I don't want to bother other users with widgets that might confuse them because they don't use the process that generates records in this table.
So, my requirement basically would be to hide the widget instance if there is no record in the custom table where the current user is either opened_by or requested_for.
I know this is probably possible by editing the widget definition (or cloning the widget and editing the clone), but I'd like to be sure that I'm not missing an easier way to do this.
Thanks for your help!
Solved! Go to Solution.
- Labels:
-
Service Portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:35 PM
Hello
Yes you need to clone the Data table from instance definition widget and replace the cloned widget in your page
After placing it in your page ,in the server script of the widget paste this
You need to build your query accordingly and put in addquery
Server script:
data.showTable =false;
var cus = new GlideRecord('your custom table');
cus.addQuery('openedbyfield name',gs.getUserID());
cus.query();
if(cus.next())
{
data.showTable = true;
}
else
{
data.showTable=false;
}
Also you need to add ng-if to the HTML div like below. Replace your script like below in HTML
<div ng-if="data.showTable==true">
<div class="alert alert-danger" ng-if="data.invalid_table">
${Table not defined} '{{data.table_label}}'
</div>
<sp-widget ng-if="data.dataTableWidget" widget="data.dataTableWidget"></sp-widget>
</div>
This will do the work
Please mark my solution correct if it helped you in anyway
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:35 PM
Hello
Yes you need to clone the Data table from instance definition widget and replace the cloned widget in your page
After placing it in your page ,in the server script of the widget paste this
You need to build your query accordingly and put in addquery
Server script:
data.showTable =false;
var cus = new GlideRecord('your custom table');
cus.addQuery('openedbyfield name',gs.getUserID());
cus.query();
if(cus.next())
{
data.showTable = true;
}
else
{
data.showTable=false;
}
Also you need to add ng-if to the HTML div like below. Replace your script like below in HTML
<div ng-if="data.showTable==true">
<div class="alert alert-danger" ng-if="data.invalid_table">
${Table not defined} '{{data.table_label}}'
</div>
<sp-widget ng-if="data.dataTableWidget" widget="data.dataTableWidget"></sp-widget>
</div>
This will do the work
Please mark my solution correct if it helped you in anyway
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2022 03:45 AM
Although I initially hoped I'd get by without cloning the widget, your suggestion was very easy to implement! Thanks for taking the time to even providing the code samples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-21-2022 02:44 PM
Hi there!
You can uncheck "Show even when empty" checkbox in instance options and if its not present then you can use "Roles" field on "sp_instance_table" of that widget.
Assign specific roles to the users whom you want to display that widget.
Regards,
Palak