The CreatorCon Call for Content is officially open! Get started here.

How to Set Widget Visibility... Service Portal

ashishgupta
Tera Expert

1. I have a requirement to have a particular widget for a special category of the Service Catalogs.

Please can you help me out in setting the visibility of particular widget over "sc_cat_item" page for a special category of the Service Catalogs.

2. Also, I want to hide the Submit Button on the "SC Catalog Item" widget for particular service Catalog.

ctomasi

pradeepksharma

b-rad

26 REPLIES 26

Hi @fschuster  and @ashishgupta 

 

i had used you code ,when i had same requirement but its didn't work can you help with this 

this is the code which i had used

HTML :

  <div class="col-xs-12 col-sm-6 col-md-4"
ng-class="{'col-md-6' : (c.data.openIncident && c.data.submitCatalog)}"
ng-if="c.data.submitCatalog || data.url_suffix || 'spc' != data.url_suffix">


<button role="button" ng-show="showCategory" class="btn btn-secondary-black" ng-click="kbSubmitRequest()">{{c.options.catalog_button_text}}</button>
</div>

 

Serverscript :

(function() {

data.showCategory = false;
//to show button for spc catalogs
var showCategory = true;
data.sc_cat_item = $sp.getCatalogItem(data.sys_id);
if (data.sc_cat_item.category) {
var categoryGR = new GlideRecord('sc_category');
categoryGR.get(data.sc_cat_item.category);
data.category = {
name: categoryGR.getDisplayValue('title'),
url: 'spc?id=ays_kb_article&source=search&sys_id=' + categoryGR.sys_id
};
if (data.category.name === "spc catelogs") {
showCategory = true;
}
}

})();

 

Any helpful thoughts and @Ankur Bawiskar can you also please look

 

Thanks 

Mounish

fschuster
ServiceNow Employee
ServiceNow Employee

In your server script, you're going to need to modify the "showCategory = true" line to "data.showCategory = true". Unless you add data to it, this variable only remains accessible in the context of your server script.

 

Then, step two, add "c.data." to your show/hide condition.

 

I'm not saying it's the wrong thing to use ng-show, but it's a good thing to keep in mind that there are tradeoffs between ng-if and ng-show, so you'll want to apply whatever makes most sense for your use-case, you can read more about it here: https://www.codelord.net/2015/07/28/angular-performance-ng-show-vs-ng-if/

Hi @fschuster 

 

herre is the code of html:

<div class="col-xs-12 col-sm-6 col-md-4"
ng-class="{'col-md-6' : (c.data.openIncident && c.data.submitCatalog)}"
ng-if="c.data.submitCatalog && data.url_suffix && 'spc' == data.url_suffix">


<button role="button" ng-show="c.data.showCategory" class="btn btn-secondary-black" ng-click="kbSubmitRequest()">{{c.options.catalog_button_text}}</button>


</div>

 

Server script:

data.showCategory = true;
//to show button for spc catalogs
var showCategory = true;
data.sc_cat_item = $sp.getCatalogItem(data.sys_id);
if (data.sc_cat_item.category) {
var categoryGR = new GlideRecord('sc_category');
categoryGR.get(data.sc_cat_item.category);
data.category = {
name: categoryGR.getDisplayValue('title'),
url: '?id=ays_kb_article&source=search&sys_id=' + categoryGR.sys_id
}
if (data.category.name == 'spc catalog') {
data.showCategory = true;
}
}
//to show button for spc catalogs till above

 

i had given as per the condition but its not working can you let me know any errors

 

Regards

Mounish

 

 

Hi Ashish,



Could you please let me know the HTML code which you used to hide the widget?



I am having a similar issue were I am trying to hide a widget if the current user is member of a particular group.



Regards,



Ashwin


mikea_s
Kilo Contributor

Ashwin,



Did you get a solution for this?