Splunk Dashboard. Multiselect depends on another multiselect - splunk-dashboard

I'm trying to get one multiselect depend to another multiselect. I have come to a point where I show the another multiselect when I select Opt1. That's how I want it. But I also want multiselect2 to appear when I select Opt1 and Opt2.
If I first select Opt1 and then Opt2, the second multiselect is displayed. But not when I select Opt2 and then Opt1. How do I make the second multiselect appear then as well?
<form theme="dark">
<label>concept</label>
<fieldset submitButton="true" autoRun="false">
<input type="multiselect" token="index">
<label>Index</label>
<choice value="opt1">Opt1</choice>
<choice value="opt2">Opt2</choice>
<change>
<condition value="opt2">
<unset token="opt1_selected"></unset>
</condition>
<condition value="opt1">
<set token="opt1_selected"></set>
</condition>
</change>
<delimiter> OR </delimiter>
<default>Opt1</default>
</input>
<input type="multiselect" token="Menu2" depends="$opt1_selected$">
<label>Multi2</label>
</input>
</fieldset>
</form>

As per experience, I have found that working with tokens is not that straightforward when submitButton attribute is set to true.
Unless the submit button is important to your use case, please see below Simple XML code where I turned that attribute to false.
<form theme="dark">
<label>Sample</label>
<init>
<set token="show">true</set>
</init>
<fieldset submitButton="false" autoRun="false">
<input type="multiselect" token="index">
<label>Index</label>
<choice value="opt1">Opt1</choice>
<choice value="opt2">Opt2</choice>
<change>
<condition match="match($index$,"opt1") OR match($index$,"opt2")">
<set token="show">true</set>
</condition>
<condition match="NOT match($index$,"opt1") OR match($index$,"opt2")">
<unset token="show">true</unset>
</condition>
</change>
<delimiter> OR </delimiter>
<default>opt1</default>
</input>
<input type="multiselect" token="Menu2" depends="$show$">
<label>Multi2</label>
</input>
</fieldset>
</form>
This solution should work with the following value combinations:
opt1,
opt1 OR opt2,
opt2, and
opt2 OR opt1.
Explanation:
The trick is in evaluating the index token which holds the final selection value(s). You can use the match attribute inside the <condition> tag which allows you to validate the token with an eval-like expression.
...
<condition match="match($index$,"opt1") OR match($index$,"opt2")">
<set token="show">true</set>
</condition>
...
The logic of this expression is to "match", or compare, the input string (value of token index) against a regex (opt1 OR opt2). Note that for this expression to work, you have to escape some characters (e.g. quotation marks into ") using HTML entities.
If a match is found, the condition is satisfied and will proceed to perform the setting of the token show.
...
<set token="show">true</set>
...
Otherwise, it will continue to the evaluate the next condition (which is basically the same expression but negated with the NOT operator), and then proceed to unset token show.
...
<condition match="NOT match($index$,"opt1") OR match($index$,"opt2")">
<unset token="show">true</unset>
</condition>
...

Related

Inserting parameters into a template loop

Is it possible to use the parameters declared in the parameters' node (see the XDT file) inside a foreach loop in the template? I'd have to add a namespace? If yes which one?
File XDT:
<dataTemplate name="StoreLayoutLabels" xmlns="http://micros.com/xstore/config/report">
<labels>
<!-- Template-specific Text -->
<label name="HANDHELD_READ" value="_art.inventory.handheld.read"/>
<label name="MANUAL_CHECK" value="_art.inventory.manual.check"/>
<label name="OPERATOR1" value="_art.inventory.operator1"/>
<label name="OPERATOR2" value="_art.inventory.operator2"/>
<label name="SECTION" value="_art.inventory.section"/>
<label name="STORE" value="_art.inventory.store"/>
</labels>
<parameters>
<!-- System Parameters -->
<parameter name="GroupName" class="java.lang.String" isForPrompting="false" include_in_output="true"/>
<parameter name="storeNbr" class="java.lang.String" isForPrompting="false" include_in_output="true"/>
<parameter name="storeName" class="java.lang.String" isForPrompting="false" include_in_output="true"/>
</parameters>
<!--Data source and data Structure-->
<dataSource>
<dataReference name="Q_STORE_LAYOUT_LABELS">
<ResultFields>
<ResultField>SectionId</ResultField>
<ResultField>SectionDescription</ResultField>
</ResultFields>
</dataReference>
</dataSource>
<dataStructure>
<group name="STORE_LAYOUT_LABELS" source="Q_STORE_LAYOUT_LABELS">
<element name="SECTION_ID" value="SectionId"/>
<element name="SECTION_DESCRIPTION" value="SectionDescription"/>
</group>
</dataStructure>
</dataTemplate>
Report template:
For example, PAR_GROUP_NAME is represented by the <?GroupName?> tag in the template but it doesn't appear after the PDF transformation. The value is shown correctly if the tag is inserted outside the label F which represents the loop.
When you reference a field, it's looking inside the element you are currently in. So you will need to tell BI Publisher where it is if it's not in the current element. Just add ../ for each level you need to go up the tree, and then once you get into the first common element, you can then go back down.
So if you are in a <?for-each:dataSource?>
You can get the parameter attribute value, where the attribute name = GroupName, by doing:
<?../parameters/parameter[#name='GroupName']?>
Reference:
https://docs.oracle.com/cd/E80149_01/bip/BIPRD/GUID-4D9FC5FC-5A72-4CE6-919C-A3E0D6E4900C.htm#BIPRD2597

Validate TFS 2017 Boolean field

I am trying to edit work item templates to make use of the new Boolean field in TFS 2017, and want a particular field to be set to true before a status can be changed. Is there any way to do this? It would appear ALLOWEDVALUES and MATCH aren't supported, which could have potentially helped
You can do that by applying a conditional rule based on your requirement just as Hamid mentioned above.
Boolean is just a data type, we can add a custom Boolean field and add a checkbox for it.
Use the following syntax to add a Boolean field within the FIELDS
section of the WIT definition.
<FIELD name="Triagelc" refname="lc.Triage" type="Boolean" >
<DEFAULT from="value" value="True" />
<HELPTEXT>Triage work item</HELPTEXT>
</FIELD>
And then add the following syntax within the FORM section to have
the field appear on the form.
<Control Label="Triagelc" Type="FieldControl" FieldName="lc.Triage" />
The field will appear as a checkbox on the form.
Then apply a When rule for target filed, thus when the specified
Boolean field has the specified value, the When rule is applied to
the target field.
eg1:
Apply a "When" rule for Description field in Task work item type :
<FieldDefinition name="Description" refname="System.Description" type="HTML">
<WHEN field="lc.Triage" value="True">
<REQUIRED />
</WHEN>
</FieldDefinition>
Then when set the value to True, the Description area is required, it cannot be empty.
eg2:
You can also use READONLY rule to restrict other areas:
<FieldDefinition name="Assigned To" refname="System.AssignedTo" type="String" syncnamechanges="true" reportable="dimension">
<WHEN field="lc.Triage" value="True">
<READONLY />
</WHEN>
<ALLOWEXISTINGVALUE />
<HELPTEXT>The person currently owning this task</HELPTEXT>
</FieldDefinition>
Thus, when the Boolean field value is True, Assigned To field is read only, otherwise you can assign to the existing users.
UPDATE:
eg3:
We can not achieve that directly with the boolean data type. As a workaround you can try below ways:
Apply the When rule and embed the Copy rule (Copy True as the
value) for the "Triagelc" boolean field in this example. Thus when
the status is Done, Triagelc can set the value to "True"
automatically, then save. But in this way the value still can be
modified to false. Reference below screenshot 1:
<FieldDefinition name="Triagelc" refname="lc.Triage" type="Boolean">
<WHEN field="System.State" value="Done">
<COPY from="value" value="True" />
</WHEN>
<HELPTEXT>Triage work item</HELPTEXT>
</FieldDefinition>
Set the default value to True for Boolean field (Triagelc
field in this example), then apply When rule with READONLY rule
embedded. This way should be meet your requirement (Once done the value cannot be changed anymore). Reference below screenshot 2:
<FieldDefinition name="Triagelc" refname="lc.Triage" type="Boolean">
<DEFAULT from="value" value="True" />
<WHEN field="System.State" value="Done">
<READONLY />
</WHEN>
<HELPTEXT>Triage work item</HELPTEXT>
</FieldDefinition>
Please note that:
The Boolean data type field is only supported for VSTS and TFS 2017.2
and later versions.
Screenshot 1:
Screenshot 2:

Setting TFS field as readonly based on area path

I have custom TFS form with a text field comment. I want this field to be readonly for most of the area paths except 4. How can I add condition to set the field as read only?
basically, when the area id is 1,2,3,4 the comment field should not be readonly else it should be readonly.
I tried the following, but it didn't work
<FIELD name="Comment" refname="test.test.comment" type="Integer">
<WHENNOT field="System.AreaId" value="1">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="2">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="3">
<READONLY />
</WHENNOT>
<WHENNOT field="System.AreaId" value="4">
<READONLY />
</WHENNOT>
</FIELD>
I dont want to write when conditions because these 4 are constant and I have about 40 other area ids which keeps increasing.
No, "And" multiple "WHENNOT" conditions doesn't work. See: Work Item state change rules in TFS - Any way to use "AND"s or "OR"s?
So, instead of using work item rules, you need to work with custom work item control. Determine when to set Comment filed to be readonly via using TFS API. Check this link for the details on how to work with custom work item control: https://witcustomcontrols.codeplex.com/

How can I make an ant prompt use the default value if not entered within a given time?

Many ant scripts I write use a default value, and these default values are almost exclusive. I.e. only occasionally will I want to run it without the default values.
A lot of times, these scripts take enough time that it makes sense to go do something else while they run, like getting coffee or using the Little Developer's Room. Of course, if there's a prompt on it, and you forgot it, well, you're SOL.
Is there any way I can put a timeout on the prompt so if it isn't entered in, oh let's say 30 seconds, that it just accepts the default value so that when I get back to my workstation I have my war/jar/whatever ready to go? Something like
<input addproperty="branch.tag"
defaultvalue="dev"
timeout="30000">
Which branch would you like to build?
</input>
Now obviously this timeout feature doesn't exist, but you get the idea of what I'm trying to accomplish.
Option 1: Configure build to run automated or interactive
Rather than timing out the input prompts, you could configure the build to run fully automated by supplying the default input values in a properties file.
default.properties
Which\ branch\ would\ you\ like\ to\ build?=dev
To switch between interactive and automated builds, the type of input handler to use could be specified when invoking Ant:
Automated build
$ ant -Dhandler.type=propertyfile
Interactive build
$ ant -Dhandler.type=default
The input handler would need to be specified using the nested <handler> element.
<input addproperty="branch.tag" defaultvalue="dev"
message="Which branch would you like to build?">
<handler type="${handler.type}" />
</input>
The last step is to specify the properties file for the PropertyFileInputHandler by defining the ant.input.properties system property.
Linux
export ANT_OPTS=-Dant.input.properties=default.properties
Option 2: Use AntContrib Trycatch combined with Parallel in a macrodef
<taskdef name="trycatch" classname="net.sf.antcontrib.logic.TryCatchTask">
<classpath>
<pathelement location="/your/path/to/ant-contrib.jar"/>
</classpath>
</taskdef>
<macrodef name="input-timeout">
<attribute name="addproperty" />
<attribute name="defaultvalue" default="" />
<attribute name="handlertype" default="default" />
<attribute name="message" default="" />
<attribute name="timeout" default="30000" />
<text name="text" default="" />
<sequential>
<trycatch>
<try>
<parallel threadcount="1" timeout="#{timeout}">
<input addproperty="#{addproperty}"
defaultvalue="#{defaultvalue}"
message="#{message}">
<handler type="#{handlertype}" />
#{text}
</input>
</parallel>
</try>
<catch>
<property name="#{addproperty}" value="#{defaultvalue}" />
</catch>
</trycatch>
</sequential>
</macrodef>
<target name="test-timeout">
<input-timeout addproperty="branch.tag" defaultvalue="dev"
message="Which branch would you like to build?"
timeout="5000" />
<echo message="${branch.tag}" />
</target>
Option 3: Write a custom Ant task
Implementation left as an exercise to the reader.

Ant propertyfile task: how can I set an integer with no thousand separators?

I have a property defined in one of my property files:
<entry key="build" default="0" type="int" operation="+" value="1" />
I read this property using:
<replacefilter token="#build#" property="build_num" />
Once this number gets bigger than 999, thousand separator commas start appearing, like this:
1,001
1,562
Is there a way to get rid of those commas?
(I use build to generate a file name, and don't really want to see any commas in there).
You can prevent thousand separators from being used by adding a pattern to the entry:
<entry key="build" default="0" type="int" operation="+" value="1" pattern="0" />
Note that you'll probably need to manually remove the commas one-time before running this - else your build numbers will reset, with the comma and subsequent digits being discarded. (So 1,325 -> 2 and 4,111 -> 5 and so on.)
Figured ###0 would have worked, but it didn't. Since the project is already making extensive use of ant-contrib, it wasn't difficult to add the regex solution Aaron suggested.
<propertyregex property="build" input="${build}" regexp="," replace="" global="true" override="true"/>

Resources