KBA-01595: Naming Automatically Attached Files from Templates

Purpose & Scope:

How to name automatically attached files from templates.

Procedure:

The system default is controlled by the template name and the TemplateAttachPrefix and TemplateAttachSuffix rules (see KBA-01265).  You should first review that information to see if it will meet your needs.

Otherwise, you can create your own add-in function for TSQL to generate a custom name.  Here’s how:

  1. Be sure you have defined the [custom] schema in SQL:

    if schema_id(‘custom’) is null  EXEC(‘CREATE Schema [custom]’);

  2. Create a function named [custom].cf_TemplateFileName that must accept 4 arguments and return VARCHAR(99)
    1. @TName is the template name
    2. @TFileType is the template extension (eg DOCX), without the leading period
    3. @pDocMasterKey is the GUID key for the document header (dbo.xsfDocHeader WHERE DocMasterKey=@pDocMasterKey) onto which the template will be attached
    4. @AATK is the GUID key for the template being used (dbo.xsfDocTemplate WHERE TemplateKey = @AATK)

This sample function basically reproduces the built-in functionality

create function [custom].cf_TemplateFileName
(  @TName VARCHAR(99)
, @TFileType VARCHAR(8)
, @pDocMasterKey UniqueIdentifier
, @AATK UniqueIdentifier
)
RETURNS VARCHAR(99)
AS
BEGIN
DECLARE @DTK UniqueIdentifier
, @DocNo VARCHAR(32)
, @Project VARCHAR(32)
SELECT @Project = RTRIM(dh.project)
, @DocNo = RTRIM(dh.DocNo )
, @DTK = dh.DocTypeKey
FROM dbo.xsfDocHeader dh
WHERE dh.DocMasterKey = @pDocMasterKey ;

if ISNULL(dbo.f_RuleResultString(‘FileCatalogConfig’, @DTK, ‘TemplateAttachPrefix’),’Project’) = ‘Project’
SET @TName = LTRIM( RTRIM( ISNULL( dbo.f_MaskString(@Project,dbo.f_SOLProjectFlexkey(‘PROJECT’)) ,”)) + ‘ ‘ + @TName )

if ISNULL(dbo.f_RuleResultString(‘FileCatalogConfig’, @DTK,’TemplateAttachSuffix’),’#’) = ‘#’
SET @TName = RTRIM( @TName + ‘ ‘ + ISNULL( dbo.f_MaskString(@DocNo, dbo.f_SOLProjectFlexkey( dbo.f_RuleResultString(‘DocTypeConfig’, @DTK,’DocNoMaskName’)) )
,”))

if not @TName like ‘%’ + @TFileType SET @TName = @TName + ‘.’ + @TFileType

RETURN (RTRIM(@TName))
END

Additional Comments:

This is an advanced topic.  Contact your implementation specialist for assistance. When you use the add-in function then the TemplateAttachPrefix and TemplateAttachSuffix rules no longer have any meaning unless your code references them for its own use.  See the example above.


KBA-01595; Last updated: September 19, 2017 at 10:07 am;