Continuing on with a look at another brand new feature of XMod Pro 3: Custom Data Commands. This feature has the potential to really open up your solutions making them significantly more functional and flexible.
What Are Custom Data Commands?
[NOTE: This is a re-posting of an older article. It includes a couple of fixes and a change suggested by a commenter]
Currently, whenever you’re displaying data (i.e., using templates) in XMod Pro, you have 3 basic types of data commands you can execute:
- List Data: The ListDataSource tag is responsible for retrieving a list of records from the database – appropriate for displaying any kind of browse-able data set.
- Detail Data: When your user clicks a link to see the details for a record, the DetailDataSource tag handles it.
- Delete Command: If the user clicks a delete link, this command gets executed.
Together, these three view-based data commands cover the vast majority of data-display scenarios for most sites. But, what if you want to provide your users with the ability to approve a record? There is no “Approve Command”. XMod Pro veterans know that, if they’re not using the Delete Command, they can re-purpose it for their custom needs. But, what if you are already using the Delete Command but still need an “Approve Command”?
The answer is to use a Custom Data Command. They are used only in Templates (views) and are defined in much the same way as the ListDataSource, DetailDataSource, and DeleteCommand. Here’s an example:
<DataCommand CommandName="ApproveRecord" CommandText="UPDATE Articles SET [email protected] WHERE [email protected]">
<Parameter Name="Approve" />
<Parameter Name="ArticleId" />
We start with the parent/container tag –
<CustomCommands>. This can house one or more
<DataCommand> tags. Each
<DataCommand> must have a name. You’ll use this when you trigger the command (more on that in a bit). Beyond that, it’s like any other data command you might use in XMod Pro. You specify a
CommandText which could be a SQL command (as in the example) or a stored procedure. Optionally, the
<DataCommand> can have one or more
<Parameter> tags to pass data into the command.
Now that you have your custom data command, how do you call it? Why, you use a command button (or image or link) like so:
<xmod:CommandButton Text="Approve Record">
<Command Name="Approve Record" Type="Custom">
<Parameter Name="Approve" Value="1" />
<Parameter Name="ArticleId" Value='[[ArticleId]]' />
In the above example, we’ve used the
<CommandButton> tag to create a button with “Approve Record” as its caption. Inside the
<CommandButton>, we can list one or more
<Command> tags. We’re using just one here. First, we need to specify the name of the command we want to trigger (refer to our DataCommand’s CommandName property) and we specify “Custom” as the Type. This tells XMod Pro to look for the ApproveRecord command in the
<CustomCommands> tag and execute it, passing any parameters you’ve defined. In this case, it will pass the value “1” to the command which, assuming the “Approve” column is a bit data type, will effectively set the record’s approval status to True.
This is just a simple example, but Custom Data Commands can greatly expand the types of solutions you can create with XMod Pro.