StandardTemplate#

NAME#

Kernel::System::StandardTemplate - standard template lib

DESCRIPTION#

All standard template functions. E. g. to add standard template or other functions.

PUBLIC INTERFACE#

new()#

create an object

my $StandardTemplateObject = $Kernel::OM->Get('Kernel::System::StandardTemplate');

StandardTemplateAdd()#

add new standard template

my $ID = $StandardTemplateObject->StandardTemplateAdd(
    Name         => 'New Standard Template',
    Template     => 'Thank you for your email.',
    ContentType  => 'text/plain; charset=utf-8',
    TemplateType => 'Answer,Forward',
    ValidID      => 1,
    UserID       => 123,
);

StandardTemplateGet()#

get standard template attributes

my %StandardTemplate = $StandardTemplateObject->StandardTemplateGet(
    ID => 123,
);

Returns:

%StandardTemplate = (
    ID                  => '123',
    Name                => 'Simple remplate',
    Comment             => 'Some comment',
    Template            => 'Template content',
    ContentType         => 'text/plain',
    TemplateType        => 'Answer,Forward',
    ValidID             => '1',
    CreateTime          => '2010-04-07 15:41:15',
    CreateBy            => '321',
    ChangeTime          => '2010-04-07 15:59:45',
    ChangeBy            => '223',
);

StandardTemplateDelete()#

delete a standard template

$StandardTemplateObject->StandardTemplateDelete(
    ID => 123,
);

StandardTemplateUpdate()#

update standard template attributes

$StandardTemplateObject->StandardTemplateUpdate(
    ID           => 123,
    Name         => 'New Standard Template',
    Template     => 'Thank you for your email.',
    ContentType  => 'text/plain; charset=utf-8',
    TemplateType => 'Answer,Forward',
    ValidID      => 1,
    UserID       => 123,
);

StandardTemplateLookup()#

return the name or the standard template id

my $StandardTemplateName = $StandardTemplateObject->StandardTemplateLookup(
    StandardTemplateID => 123,
);

or

my $StandardTemplateID = $StandardTemplateObject->StandardTemplateLookup(
    StandardTemplate => 'Std Template Name',
);

StandardTemplateExport()#

export a standard template

my $ExportData = $StandardTemplateObject->StandardTemplateExport(
    # required either ID or ExportAll
    ID                       => $StandardTemplateID,
    ExportAll                => 0,               # possible: 0, 1

    UserID                   => 1,               # required
}

returns Standard Template hashes in an array with data:

my $ExportData =
[
    {
        'ValidID' => 1,
        'Template' => '<p>some-content</p>',
        'CreateBy' => 1,
        'Name' => 'create1',
        'TemplateType' => 'Create',
        'Comment' => '',
        'Queues' => {},
        'ChangeBy' => 1,
        'ID' => '24',
        'Attachments' => {
            '1' => 'attachment1',
            '2' => 'attachment2'
        },
        'CreateTime' => '2024-07-24 09:47:28',
        'ContentType' => 'text/html',
        'ChangeTime' => '2024-07-24 09:53:25'
    },
];

StandardTemplateImport()#

import a standard template via YAML content

my $ImportResult = $StandardTemplateObject->StandardTemplateImport(
    Content                    => $YAMLContent, # mandatory, YAML format
    OverwriteExistingTemplates => 0,            # optional, possible: 0, 1
    UserID                     => 1,            # mandatory
);

Returns:

$Result = {
    Success          => 1,                                      # 1 if success or undef if operation could not
                                                                # be performed
    Message          => 'The Message to show.',                 # error message
    Added            => 'StandardTemplate1, StandardTemplate2', # string of StandardTemplates correctly added
    Updated          => 'StandardTemplate3, StandardTemplate4', # string of StandardTemplates correctly updated
    NotUpdated       => 'StandardTemplate5, StandardTemplate6', # string of StandardTemplates not updated due to existing entity
                                                                # with the same name
    Errors           => 'StandardTemplate5',                    # string of StandardTemplates that could not be added or updated
    AdditionalErrors => ['Some error occured!', 'Error2!'],     # list of additional error not necessarily related to specified StandardTemplate
};

StandardTemplateCopy()#

copy a standard template without linking it to any queue/attachment

my $NewStandardTemplateID = $StandardTemplateObject->StandardTemplateCopy(
    ID     => 1, # mandatory
    UserID => 1, # mandatory
);

StandardTemplateExportDataGet()#

get data to export standard template

my %StandardTemplateData = $StandardTemplateObject->StandardTemplateExportDataGet(
    ID => 1, # mandatory
);

Returns:

my %StandardTemplateData = (
    {
       'ValidID' => 1,
       'CreateBy' => 1,
       'Template' => '<p>some-content</p>',
       'Name' => 'create1',
       'TemplateType' => 'Create',
       'Queues' => {},
       'ChangeBy' => 1,
       'ID' => '24',
       'Comment' => '',
       'Attachments' => {
            '1' => 'attachment1',
            '2' => 'attachment2'
        },
        'CreateTime' => '2024-07-24 09:47:28',
        'ChangeTime' => '2024-07-24 09:53:25',
        'ContentType' => 'text/html'
    };
);

StandardTemplateExportFilenameGet()#

get export file name based on standard template name

my $Filename = $StandardTemplateObject->StandardTemplateExportFilenameGet(
    Name => 'StandardTemplate_1',
    Format => 'YAML',
);

StandardTemplateQueuesList()#

get a list of the queues that have been linked to standard template

my %StandardTemplateQueues = $StandardTemplateObject->StandardTemplateQueuesList(
    ID => 1, # mandatory
);

Returns:

my %StandardTemplateQueues = (
    1 => 'queue1',
    2 => 'queue2',
)

StandardTemplateAttachmentsList()#

get a list of attachments that have been linked to standard template

my %StandardTemplateAttachments = $StandardTemplateObject->StandardTemplateAttachmentsList(
    ID => 1, # mandatory
);

Returns:

my %StandardTemplateAttachments = (
    1 => 'attachment1',
    2 => 'attachment2',
)

StandardTemplateQueueLinkByTemplate()#

assign a list of queues to a template

my $Success = $StandardTemplateObject->StandardTemplateQueueLinkByTemplate(
    QueueIDs => [1,2,3],
    ID       => 1,
    UserID   => 1,
);

StandardTemplateAttachmentLinkByTemplate()#

assign a list of attachments to a template

my $Success = $StandardTemplateObject->StandardTemplateAttachmentLinkByTemplate(
    AttachmentIDs => [1,2,3],
    ID            => 1,
    UserID        => 1,
);

StandardTemplateList()#

get all valid standard templates

my %StandardTemplates = $StandardTemplateObject->StandardTemplateList();

Returns:

%StandardTemplates = (
    1 => 'Some Name',
    2 => 'Some Name2',
    3 => 'Some Name3',
);

get all standard templates

my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
    Valid => 0,
);

Returns:

%StandardTemplates = (
    1 => 'Some Name',
    2 => 'Some Name2',
);

get standard templates of a single type

my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
    Valid => 0,
    Type  => 'Answer',
);

Returns:

%StandardTemplates = (
    1 => 'Some Name',
);

get standard templates for multiple types

my %StandardTemplates = $StandardTemplateObject->StandardTemplateList(
    Valid => 0,
    Type  => 'Answer,Forward',
);

Returns:

%StandardTemplates = (
    'Answer' => {
        '1' => 'Some Name',
        '4' => 'AW FWD',
    },
    'Forward' => {
        '3' => 'Some Name3',
        '4' => 'AW FWD',
    }
);

NameExistsCheck()#

return 1 if another standard template with this name already exists

    $Exist = $StandardTemplateObject->NameExistsCheck(
        Name => 'Some::Template',
        ID   => 1,                  # optional
    );