Create an Add Data Form Extension

You can extend a data form with the SDK or create an attribute extension through the user interface. For more information about data form extensions, see Data Form Extensions.

SDK Data Form Extensions

Attribute Extensions

SDK Data Form Extensions

To extend a data form, create another data form of the same type and use the DataFormExtension element. The DataFormExtension element has two required attributes: DataFormInstanceID and TabCaption. The DataFormInstanceID attribute relates the extension to the form to be extended. The TabCaption attribute specifies the caption for the tab or the section header depending on what is specified for the optional RenderStyle attribute. RenderStyle specifies how to render the extension, as a tab or a section following the sections on the form to be extended. To localize the TabCaption, you can use TabCaptionResourceKey together with a resources file.

For Add Data Form extensions, a Context element is required and load implementations are not supported. Context relates the data form extension to the record added by the form to be extended. The context is passed to the data form extension by the form that is extended. For Add Data Forms, the ID returned upon saving the extended form is passed to the data form extension. For stored procedure implementations, a parameter for the stored procedure should correspond to a value specified in the RecordIDParameter attribute of the Context element. RecordIDParameter is not used for Common Language Runtime implementations. A value for the ContextRecordType attribute is also required.

When a data form extension is loaded, it is rendered on the form it extends.

Table Extension Scenario

Consider an Add Data Form that inserts records into a table with three fields. To extend the table, you can create a second table with other fields and a foreign key field to the first table.

Figure: First Table

<TableSpec
	xmlns="bb_appfx_table"
	xmlns:common="bb_appfx_commontypes"
	ID="644c1145-32ba-4667-981d-f0e9c0525ad7"
	Name="Example1"
	Description="Stores information about example1 records"
	Author="Technical Training"
	Tablename="USR_EXAMPLE1"
	IsBuiltIn="false"
	>

  <Fields>
    <TextField Name="FIELD1" Length="50"/>
    <TextField Name="FIELD2" Length="50"/>
  </Fields>

</TableSpec>

Figure: Second Table

<TableSpec
	xmlns="bb_appfx_table"
	xmlns:common="bb_appfx_commontypes"
	ID="6d9af0ce-9ef7-4438-bd8e-9360bba120cb"
	Name="Example2"
	Description="Stores information about example2 records"
	Author="Technical Training"
	Tablename="USR_EXAMPLE2"
	IsBuiltIn="false"
	>

  <Fields>
    <TextField Name="FIELD3" Length="50"/>
    <TextField Name="FIELD4" Length="50"/>
    <ForeignKeyField Name="USR_EXAMPLE1ID" ForeignTable="USR_EXAMPLE1"/>
  </Fields>

</TableSpec>

If an Add Data Form for the first table already exists, you can extend it to include fields to insert into the second table.

Figure: First Data Form

<AddDataFormTemplateSpec
	xmlns="bb_appfx_adddataformtemplate"
	xmlns:common="bb_appfx_commontypes"
	ID="b696e1ea-3df8-48b9-8860-a202204743d3"
	Name="Example1 Add Data Form"
	Description="A data form for adding example1 records"
	Author="Technical Training"
	DataFormInstanceID="bb1fb0ca-7a7e-4608-991f-be99bf949c65"
	RecordType="Example1"
	common:SecurityUIFolder="Example1"
	FormHeader="Add an example1"
	>

  <SPDataForm>
    <SaveImplementation SPName="USR_USP_DATAFORMTEMPLATE_ADD_EXAMPLE1">
      <common:CreateProcedureSQL>
        <![CDATA[
create procedure dbo.USR_USP_DATAFORMTEMPLATE_ADD_EXAMPLE1 (
	@ID uniqueidentifier = null output,
	@CHANGEAGENTID uniqueidentifier = null,
	@FIELD1 nvarchar(50) = '',
	@FIELD2 nvarchar(50) = ''
	)
as
set nocount on;

if @ID is null
	set @ID = newid()

if @CHANGEAGENTID is null
	exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime

set @CURRENTDATE = getdate()

begin try
	-- handle inserting the data
	insert into dbo.[USR_EXAMPLE1] (
		ID,
		FIELD1,
		FIELD2,
		ADDEDBYID,
		CHANGEDBYID,
		DATEADDED,
		DATECHANGED
		)
	values (
		@ID,
		@FIELD1,
		@FIELD2,
		@CHANGEAGENTID,
		@CHANGEAGENTID,
		@CURRENTDATE,
		@CURRENTDATE
		)
end try

begin catch
	exec dbo.USP_RAISE_ERROR

	return 1
end catch

return 0				
				] ]>
      </common:CreateProcedureSQL>
    </SaveImplementation>
  </SPDataForm>

  <common:FormMetaData>
    <common:FormFields>
      <common:FormField FieldID="FIELD1" Caption="Field 1" DataType="String" MaxLength="50" />
      <common:FormField FieldID="FIELD2" Caption="Field 2" DataType="String" MaxLength="50" />
    </common:FormFields>
  </common:FormMetaData>

</AddDataFormTemplateSpec>

Figure: Second Data Form

<AddDataFormTemplateSpec
	xmlns="bb_appfx_adddataformtemplate"
	xmlns:common="bb_appfx_commontypes"
	ID="96328153-943f-4a09-82a5-ba022fc81569"
	Name="Example2 Add Data Form"
	Description="A data form for adding example2 records"
	Author="Technical Training"
	DataFormInstanceID="5dfa7b2c-2365-440f-bb98-4b3a5d2335fe"
	RecordType="Example2"
	common:SecurityUIFolder="Example2"
	FormHeader="Add an example2"
	>

  <SPDataForm>
    <SaveImplementation SPName="USR_USP_DATAFORMTEMPLATE_ADD_EXAMPLE2">
      <common:CreateProcedureSQL>
        <![CDATA[
create procedure dbo.USR_USP_DATAFORMTEMPLATE_ADD_EXAMPLE2 (
	@ID uniqueidentifier = null output,
	@CONTEXTID uniqueidentifier,
	@CHANGEAGENTID uniqueidentifier = null,
	@FIELD3 nvarchar(50) = '',
	@FIELD4 nvarchar(50) = ''
	)
as
set nocount on;

if @ID is null
	set @ID = newid()

if @CHANGEAGENTID is null
	exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

declare @CURRENTDATE datetime

set @CURRENTDATE = getdate()

begin try
	-- handle inserting the data
	insert into dbo.[USR_EXAMPLE2] (
		ID,
		FIELD3,
		FIELD4,
		ADDEDBYID,
		CHANGEDBYID,
		DATEADDED,
		DATECHANGED
		)
	values (
		@ID,
		@FIELD3,
		@FIELD4,
		@CHANGEAGENTID,
		@CHANGEAGENTID,
		@CURRENTDATE,
		@CURRENTDATE
		)
end try

begin catch
	exec dbo.USP_RAISE_ERROR

	return 1
end catch

return 0				
				] ]>
      </common:CreateProcedureSQL>
    </SaveImplementation>
  </SPDataForm>

  <Context ContextRecordType="Example1" RecordIDParameter="CONTEXTID"/>

  <common:FormMetaData>
    <common:FormFields>
      <common:FormField FieldID="FIELD3" Caption="Field 3" DataType="String" MaxLength="50" />
      <common:FormField FieldID="FIELD4" Caption="Field 4" DataType="String" MaxLength="50" />
    </common:FormFields>
  </common:FormMetaData>

  <common:DataFormExtension DataFormInstanceID="bb1fb0ca-7a7e-4608-991f-be99bf949c65"
                            TabCaption="Extension"/>

</AddDataFormTemplateSpec>

Attribute Extensions