UFN_DATAFORMINSTANCE_EXTENSIONISVALID
Returns a bit value indicating whether or not the extension is valid for the given data form instance.
Return
Return Type |
---|
bit |
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@PARENTDATAFORMINSTANCEID | uniqueidentifier | IN | |
@EXTENSIONDATAFORMINSTANCEID | uniqueidentifier | IN |
Definition
Copy
create function dbo.UFN_DATAFORMINSTANCE_EXTENSIONISVALID
(
@PARENTDATAFORMINSTANCEID uniqueidentifier,
@EXTENSIONDATAFORMINSTANCEID uniqueidentifier
)
returns bit
with execute as caller
as
begin
declare @PARENTRECORDTYPEID uniqueidentifier
declare @EXTENSIONRECORDTYPEID uniqueidentifier
declare @PARENTCONTEXTRECORDTYPEID uniqueidentifier
declare @EXTENSIONCONTEXTRECORDTYPEID uniqueidentifier
declare @PARENTMODE smallint
declare @EXTENSIONMODE smallint
declare @type1 uniqueidentifier
declare @type2 uniqueidentifier
-- a form cannot extend itself
if @PARENTDATAFORMINSTANCEID = @EXTENSIONDATAFORMINSTANCEID
return 0
-- grab the mode and recordtypes associated with the forms
select @PARENTRECORDTYPEID = DFT.RECORDTYPEID, @PARENTCONTEXTRECORDTYPEID = DFT.CONTEXTRECORDTYPEID, @PARENTMODE = DFT.MODE
from dbo.DATAFORMINSTANCECATALOG DFI inner join dbo.DATAFORMTEMPLATECATALOG DFT on DFI.DATAFORMTEMPLATECATALOGID = DFT.ID
where DFI.ID = @PARENTDATAFORMINSTANCEID
select @EXTENSIONRECORDTYPEID = DFT.RECORDTYPEID, @EXTENSIONCONTEXTRECORDTYPEID = DFT.CONTEXTRECORDTYPEID, @EXTENSIONMODE = DFT.MODE
from dbo.DATAFORMINSTANCECATALOG DFI inner join dbo.DATAFORMTEMPLATECATALOG DFT on DFI.DATAFORMTEMPLATECATALOGID = DFT.ID
where DFI.ID = @EXTENSIONDATAFORMINSTANCEID
-- if the mode differs, then the extension is invalid
if @PARENTMODE <> @EXTENSIONMODE
return 0
if @PARENTMODE = 2
begin
-- for add forms, check the parent record type against the extension context record type
set @type1 = @PARENTRECORDTYPEID
set @type2 = @EXTENSIONCONTEXTRECORDTYPEID
end
else
begin
-- for edit and view forms, just compare the record types
set @type1 = @PARENTRECORDTYPEID
set @type2 = @EXTENSIONRECORDTYPEID
end
-- if the record types match, then the extension is valid
if @type1 = @type2
return 1
-- if the record types are compatible, then the extension is valid
if exists(select ID
from dbo.RECORDTYPECOMPATIBILITYMAP
where (RECORDTYPE1ID = @type1) and (RECORDTYPE2ID = @type2))
return 1
else
if exists(select ID
from dbo.RECORDTYPECOMPATIBILITYMAP
where (RECORDTYPE1ID = @type2) and (RECORDTYPE2ID = @type1))
return 1
-- the extension is not valid
return 0;
end