Carousel images on the portal with condition

Aniko Hegedus
Tera Expert

Hello Everyone,

I had the requirement to display carousel images on the portal on the basis of the user's language. I had to do quite a bit of research and got inspired by @shloke04 's response until I was able to come up with my solution. I'm sharing this solution with the community, because it can be used for any other conditions and may prove to be useful for someone.

 

1. For me the condition was the user's language, so I added a new field to the Carousel Slide (sp_carousel_slide) table, called u_language and I populate it when I add a new image to my carousel.

2. Clone the OOB Carousel widget and modify the server script as per below:

//data.slides = $sp.getRelatedList('sp_carousel_slide','carousel');

// get user's language
var lang = gs.getSession().getLanguage();

data.slides = getSlideDetails();
	
	function getSlideDetails(){
		var slideDetails = [];
		var gr = new GlideRecord('sp_carousel_slide');
		gr.addQuery('carousel', <sys_id of your carousel>);
		gr.addQuery('u_language',lang); // add your condition here
		gr.query();
		while(gr.next()){
			var obj = {};
			obj.name = gr.name.toString();
			obj.url = gr.url.toString();
			obj.background = gr.background.toString() + ".iix";
			slideDetails.push(obj);
	}
		return slideDetails;
	}


This should display the images correctly.
Aniko

0 REPLIES 0