Show Hide SP Widget based on Condition

Suz Roque
Tera Expert

Hi, I am just starting to study the Service Portal.

  I have a requirement where a widget "C" needs to Show/Hide based on the Selected menu in the portal. Our client has a customized portal. If Menu selected is "Logistics", under Training & Competency menu this widget needs to Show.

Can anyone help me add that logic in below code.. Thank you! 



Server script

 

(function() {

// Template
options.template = options.template || options.u_template_dv;

options.height = options.height || '150px';

// Generate Count - optional
if (options.count_table) {
var count = new GlideAggregate(options.count_table);
if (options.count_encoded_query)
count.addEncodedQuery(options.count_encoded_query)
count.addAggregate('COUNT');
count.query();
data.count = 0;
if(count.next())
data.count = count.getAggregate('COUNT');
}

data.show_panel = (options.show_panel == "true");
data.show_bg_color = (options.background_color == "true");
if (!options.color)
options.color = "default";

data.panel_class = "";
if (data.show_panel){
data.panel_class = "panel panel-default";
}

data.background_class = "";
if (data.show_bg_color) {
data.background_class = "bg bg-"+options.color;
}

data.image = options.u_image || options.image;

data.hasInstance = ($sp.getValue('sp_column'));
if (data.hasInstance) {
var gr = $sp.getInstanceRecord();
if (gr) {
data.href = $sp.getMenuHREF(gr);
data.target = options.target || "";
}
}

})();

 

Client Controller

 

function($rootScope, $interpolate) {
var c = this;

c.setBroadcast = function() {
if (c.options.eventname)
$rootScope.$broadcast(c.options.eventname);
}

c.setCount = function(count) {
c.setCountText(count);
c.data.count = count;
}

c.setCountText = function(count) {
var context = {count: count};
if (c.options.title) {
var title = $interpolate(c.options.title);
c.options.title = title(context);
}
if (c.options.short_description) {
var description = $interpolate(c.options.short_description);
c.options.short_description = description(context);
}
};

if (c.options.count_table) {
c.setCountText(c.data.count);
}

if (c.options.subscribe_event) {
$rootScope.$on(c.options.subscribe_event, function(evt, count) {
c.setCount(count);
});
}

if (c.options.rootscope_property) {
$rootScope.$watch(c.options.rootscope_property, function (newCount, oldCount) {
if (!isNaN(newCount)) {
c.setCount(newCount);
}
})
}

}

1 REPLY 1

Allen Andreas
Administrator
Administrator

Hello,

That's quite the task to be assigned when you're new to the Service Portal.

With that said, please use the appropriate forum feature: "Insert/Edit code sample" when pasting code so that it remains organized and easier to read, especially with widget code as there's many parts:

AllenAndreas_0-1677641885909.png

Outside of that, you've censored the screenshot pretty much entirely, but where is it "captured" that they've clicked a link under a certain menu. There has to be "something" to tap into to know that they've clicked an option under a specific menu. Please tell us more about how you think this could be done? Especially if you're marking/censoring out pieces that could potentially help us help you because again, in the screenshot you've provided, the only thing we can see is a shape of a widget that you've circled and called "C".


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!