Welcome to the Learning Center

The Guide | Knowledge Base | FAQ

Browse it all or refine your selection using the filters below on the left.

Command Your Data in XMod Pro 3

See how to use a Custom Data Command to provide your users with the ability to approve a record.

By: Kelly Ford On: 05/21/2011

Link to this Article

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:

  1. 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.
  2. Detail Data: When your user clicks a link to see the details for a record, the DetailDataSource tag handles it.
  3. 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 Approve=@Approve WHERE ArticleId=@ArticleId">
			<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.