How to show/hide custom widget for specific portals

Debavelaere Tho
Kilo Contributor

Hi Community,

I created one widget with body html to add security information on sc_cat_item of our front office portal.

<div class="panel panel-primary">
 <div class="panel-heading">${Security Informations}</div>
 <div class="panel-body">
   ${Please be careful, all information in your request will be readable by everyone so don't put any sensitive information (passwords, etc.). Thank you}
 </div>
</div>

Now i want to activate this plugin information only for one portal, sc_cat_item is global use and i don't know how to do it easily...

Someone to help me ? šŸ™‚

Thanks

1 ACCEPTED SOLUTION

Justin77
Mega Guru

I think you have two options:

1.

Utilize $sp.getPortalRecord() in your widget's server script, like so:

data.isOnSpecificPortal = $sp.getPortalRecord().getUniqueValue() == '{sys id of the portal you want this information to appear on}';

From there, you can check "data.isOnSpecificPortal" from your html in an ng-if, like so:

<div class="panel panel-primary" ng-if="data.isOnSpecificPortal">

 

2.

Use AngularJS's $locationservice in the client controller by injecting it and calling it like so:

c.isOnSpecificPortal = $location.path().indexOf('{URL suffix of the specific Service Portal}') > -1);

And the you can check c.isOnSpecificPortal in your html:

<div class="panel panel-primary" ng-if="c.isOnSpecificPortal">

 

Documentation links:

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GSPS-getPortalRecord

 

https://docs.angularjs.org/api/ng/service/$location

View solution in original post

1 REPLY 1

Justin77
Mega Guru

I think you have two options:

1.

Utilize $sp.getPortalRecord() in your widget's server script, like so:

data.isOnSpecificPortal = $sp.getPortalRecord().getUniqueValue() == '{sys id of the portal you want this information to appear on}';

From there, you can check "data.isOnSpecificPortal" from your html in an ng-if, like so:

<div class="panel panel-primary" ng-if="data.isOnSpecificPortal">

 

2.

Use AngularJS's $locationservice in the client controller by injecting it and calling it like so:

c.isOnSpecificPortal = $location.path().indexOf('{URL suffix of the specific Service Portal}') > -1);

And the you can check c.isOnSpecificPortal in your html:

<div class="panel panel-primary" ng-if="c.isOnSpecificPortal">

 

Documentation links:

https://developer.servicenow.com/app.do#!/api_doc?v=madrid&id=r_GSPS-getPortalRecord

 

https://docs.angularjs.org/api/ng/service/$location