Applying Styles

Hi

I am using the following script to apply an existing style, but it doesn’t work. What I am doing wrong?

var OffButton = dundas.entities.StyleService.getStyleById(“87b6e62c-1eef-4630-906e-a23d31935f56”);
button2.applyStyle(OffButton);

Please advice

Thanks

Hi Reynaldo,

dundas.entities.StyleService is a type and its methods aren’t static, so you’ll need to get the service instance instead. Almost every instance you can access in the script editor has a getService method, so you can just call this.getService on the control, dashboard, etc. that you added the script to.
https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/view/controls/Adapter/Methods/getService.html

The getStyleById method needs to return a jQuery promise object, because it may need to download the style from the server. You can give the promise object a function that will be passed the actual style instead.
https://www.dundas.com/support/api-docs/js/#API%20Reference/dundas/entities/StyleService/Methods/getStyleById.html
http://api.jquery.com/Types/#Promise

Hopefully this script works:
var styleService = this.getService("StyleService");
var promise = styleService.getStyleById("87b6e62c-1eef-4630-906e-a23d31935f56");
promise.done(function (style) {
button2.applyStyle(style);
});

Jamie

Thanks so much for your help! That works perfectly
Thanks for the documentation reference.

Rey

No problem, glad it helped!