- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am passing URL parameters to a view built with Django and the web framework in Splunk 6. Among those paramters are the earliest and latest time, which I need to apply to the TimeRangeView on the page. That works, too, but only if the timerange does not have a preset. If if does, the value my code sets is overwritten a few hundred milliseconds later by the preset value.
This is my code:
content block:
{% timerange id="timerange1" managerid="search1" preset="Today" earliest_time="$earlyval$"|token_safe latest_time="$lateval$"|token_safe %}
js block:
var deps =
[
"splunkjs/ready!",
"splunkjs/mvc/timerangeview"
];
require(deps, function(mvc)
{
// Get the parameters
var paramEarliest = getParameterByName("earliest");
var paramLatest = getParameterByName("latest");// Set the timerange
if (paramEarliest != "" && paramLatest != "")
{
var timerange = splunkjs.mvc.Components.getInstance("timerange1");
timerange.settings.set("value", {"earliest_time" : paramEarliest, "latest_time" : paramLatest});
}
});
How can wait until the preset has been applied before I set my custom values?
Alternatively: how can I disable the preset in my script?
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I've coded up a sample that conditionally either sets a preset or sets a specific value:
https://gist.github.com/davidfstr/eb7fdf952d4648b4957c
In general you should be using timerange.settings
to alter the properties of a TimeRangeView (or any component) after it is initialized. Any underscore-prefixed field or method like timerange._state
is private and may change without warning in future framework versions.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

I've coded up a sample that conditionally either sets a preset or sets a specific value:
https://gist.github.com/davidfstr/eb7fdf952d4648b4957c
In general you should be using timerange.settings
to alter the properties of a TimeRangeView (or any component) after it is initialized. Any underscore-prefixed field or method like timerange._state
is private and may change without warning in future framework versions.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

You're right about view.settings not being documented. It should be. I'll get on that.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Would it be correct to say that a preset configured in Django cannot be overwritten in JavaScript?
It should be reconfigurable. The original code was actually hitting an unrelated bug that prevented changes to {earliest_time, latest_time} during initialization time if no "value" property was set. This bug should be fixed in the next Splunk release.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I replaced timerange._state with timerange.settings in the question.
- Mark as New
- Bookmark Message
- Subscribe to Message
- Mute Message
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks - "settings.set" is certainly better; I would have used it if it were documented!
Your script shows a nice workaround to having a preset and a custom timerange. Would it be correct to say that a preset configured in Django cannot be overwritten in JavaScript?
