Script To Change Properties in Template Layers

In a dashboard, in reaction to user actions, I want to be able to change the color of several rectangles and labels from the dashboard’s template.

Once I have the object, I know how to change its color.

I know the script name of the layer and of the controls in the layer. I am not sure how to get at the template layer objects.

I am more of a back end developer. A pointers to understanding how use the various dundas.context. ‘services’ would be great. It is difficult to know which to use from just the API reference. I am sure something will let me access what I want.

Thanks.

Hi Tallan,

You can use the templateAdapters array property to access the objects of the template layer using scripting. Please find a sample below to change the text and background color of a label which is part of a template. This script can be called from the ‘Ready’ event of the dashboard in which the template is being used.

this.templateAdapters[0].labelText = “HELLO WORLD”;

this.templateAdapters.first(function(a) { return a.name == “label1”; }).background = dundas.controls.Color.fromString(“Red”);

This is what it would like when you view it.

To change the background color of the rectangle, the sample code will be as below:

var adapters = this.templateAdapters;
for(let i=0; i < adapters.length; i++)
{
if (adapters[i].friendlyName == ‘rectangle 1’)
{
console.log(adapters[i]);
adapters[i].fill = new dundas.controls.SolidColorBrush(‘Red’);

}
}

Hope this helps.

Thanks!

1 Like

That does help! I had found this (see below), that let me get at things in the View, but found it didn’t let me access elements from the template. I should be able to use what you sent, along with this, more compact syntax, to hopefully get at the component I need. Thanks.

var element = window.parent.dundas.context.baseViewService.currentView.control.adapters.toEnumerable().first(function(adapter){return adapter.name === “label1”;});