Custom Script Token (Video Tip)

In manufacturing, you often have several shifts and you might want to create a token to easily see data for a particular shift on your dashboard.

Here is a walkthrough:

My script from the video:
DateTime[] dates = new DateTime[2];

//Get the start of today at 12:00AM
DateTime today = DateTime.Today.Date;            

//Start today at 8am
dates[0] = new DateTime(today.Year, today.Month, today.Day, 8, 0, 0);

//End today at 4pm
dates[1] = new DateTime(today.Year, today.Month, today.Day, 16, 0, 0);

//return date range;
return dates;

Other great resources for this topic:
https://www.dundas.com/resources/off-the-charts-tips-from-an-expert/elevate-your-dashboards-reports/use-tokens-to-make-your-dashboards-smart

https://www.dundas.com/resources/off-the-charts-tips-from-an-expert/getting-started-with-dundas-bi/how-to-create-custom-tokens-dundas-bi

https://www.dundas.com/support/learning/documentation/create-view-content/filters/creating-custom-tokens

****If you’re interested in the Visual Studio Code application that I use for debugging the C# code, this is a great video to help you get set up.
Here:https://channel9.msdn.com/Blogs/dotnet/Get-started-VSCode-Csharp-NET-Core-Windows

4 Likes

There is a full sample here if you’d like to play with this concept. I have also added some buttons that script the selection of these tokens.

3 Likes

Great stuff thanks Jeff!

My pleasure, @patrick. Appreciate the feedback.

Thanks Jeff, nice Tip

ahh!! this demo is exactly what I’m looking for, but I can’t get in to see the code behind those buttons. How can I get to it?

EDIT: so after I asked, I remembered that you often put debugger; in your button scripts, so I tried the console. Got it. Now I just need to extract the json and I should have it.

Hi Ken - remember the JSON trick from this video? That’s how I did it.

Here is the code behind the first button - the others are basically the same.

var viewParameter = this.parentView.control.getViewParameterByName("viewParameter1");
var token = "{\"__classType\":\"dundas.data.ParameterToken\",\"id\":\"b3eabc35-daa6-41c6-9950-9091c3f49163\",\"caption\":\"\\\"A\\\" Shift Today\",\"offset\":0,\"displayType\":\"RangeFull\",\"dataType\":\"Date\",\"isResolvable\":true,\"isOffsetSupported\":false,\"isInversionSupported\":true,\"category\":\"Script\"}";
viewParameter.parameterValue.token = JSON.parse(token);
viewParameter.refreshAllAdapters();
1 Like