With BaseExtensions, we are able to control action with an "if" command. In this way, it is possible to affect other commands.
Configuration
CMD
<Cmd case="BaseExtensions:If" if-N-type="x" if-N-key="x" if-N-value="x" />
Parameters
N
defines any number larger than -1 (0, 1, ..... 9999).
if-N-type
Define a supported type of element. See supported elements here.
if-N-key
Define name of document property.
if-N-value
Define value of document property. This field is optional. If it is not present, any value for the document property will be accepted (empty included).
Extended support for "if" command
We are able to extend this feature with True/False children. Here is an example:
<Cmd case="BaseExtensions:If" if-1-type="documentprop" if-1-key="cc" if-1-value="true"> <True> <Cmd case="BaseExtensions:find-next-cc" skipNamedFields="true" /> </True> <False> <Cmd case="BaseExtensions:find-next-field"/> </False> </Cmd>
If the result in our "if" command is evaluated to true, the true branch of commands will be executed. Likewise, if the result is false, then the false branch of commands will be executed.
Cancel commands when "if" is false
This feature can be used to cancel the remaining commands if the "if" command evaluates to false. Thus, if the document property command does not exists, it will abort case handling chain.
Requires Alloy 0.12.0 or newer for the "IF" command to actually cancel.
Here is an example:
<event type="BaseExtensions:NewDocument">
<Cmd case="BaseExtensions:If" if-1-type="documentprop" if-1-key="LayoutColor" if-1-value="Title Slide - Black"/>
<Cmd case="BaseExtensions:delete-content" type="slide" identifier="FrontPagePictureWhite"/>
</event>
As seen in this example, the second command will be cancelled, if the document property "LayoutColor" with "Title Slide - Black" as value does not exist. If it exists, the second command will be executed.
Comparison between document properties
The "if" command can be used to compare various document properties. The purpose is to be able to perform actions if two document properties are equal or not equal. In this case, use DOCUMENTPROPEQUALS
as type element, as this will compare the document properties.
Here is an example:
<Cmd case="BaseExtensions:If" if-1-type="DOCUMENTPROPEQUALS" if-1-key-1="test1" if-1-key-2="test2">
<True>
<Cmd case="BaseExtensions:AlertOk" />
</True>
</Cmd>
If the two document properties test1
and test2
are equal, the command turns out to be true
and will execute the true branch. In this example, nothing would happen if the document properties weren't equal. If there was a false branch of commands, these would be executed instead.
This can also be done with the type DOCUMENTDATA
. Here is an example:
<Cmd case="SkabelonDesign.DocumentData:DefineData" variableName="Module.Participants"> <Outlook.To> <Outlook.FirstName/> <Outlook.LastName/> <Separator> <s>, </s> </Separator> </Outlook.To> <s/> </Cmd> <Cmd case="BaseExtensions:If" if-1-type="DOCUMENTDATA" if-1-key-1="Module.Participants" if-1-value-1="Participant1" if-1-value-2="Participant2"> <True> <Cmd case="BaseExtensions:AlertOk" /> </True> </Cmd>
In this example, the first command defines data in the variable Module.Participants
. Read more about that in this article. The second command checks whether the values Participant1
and Participant2
are present. If that turns out to be true
, the command will execute the true branch.
Comments
0 comments
Article is closed for comments.