Skip to content

[Event Request][codeunit][1890][Reminder Communication]OnBeforeInsertReminderAttachmentTextLine #29774

@panagiotatsitsikaceg

Description

@panagiotatsitsikaceg

Why do you need this change?

When the user selects the action TransferOldTexts/ 'Transfer texts' on page 837 "Reminder Terms List" the existing reminder texts are copied to the new communication tables. The values of the fields added via table extension to table 294 "Reminder Text" are not transferred.

We need an event to transfer the values of the fields added via table extension to table 294 "Reminder Text" to table 504 "Reminder Attachment Text Line".

Describe the request

We would like to request an event to the internal procedure TransferReminderText(), codeunit 1890 "Reminder Communication" as follows:

    /// Subscribe to this event to transfer custom fields from Reminder Text extensions to Reminder Attachment Text Line extensions.
    /// </summary>
    /// <param name="ReminderText">Source record containing the legacy reminder text data.</param>
    /// <param name="ReminderAttachmentTextLine">Target record to be inserted with the new reminder attachment text line data.</param>
    [IntegrationEvent(false, false)]
    local procedure OnBeforeInsertReminderAttachmentTextLine(var ReminderText: Record "Reminder Text"; var ReminderAttachmentTextLine: Record "Reminder Attachment Text Line")
    begin
    end;
    internal procedure TransferReminderText()
    var
        ReminderLevels: Record "Reminder Level";
        ReminderText: Record "Reminder Text";
        ReminderAttachmentText: Record "Reminder Attachment Text";
        ReminderAttachmentTextLine: Record "Reminder Attachment Text Line";
        ReminderEmailText: Record "Reminder Email Text";
        Language: Codeunit Language;
        TypeHelper: Codeunit "Type Helper";
        ReadStream: InStream;
        DefaultLanguageCode: Code[10];
        LocalGuid: Guid;
    begin
        if ReminderText.IsEmpty() then
            exit;
        DefaultLanguageCode := Language.GetUserLanguageCode();
        ReminderText.FindSet();
        repeat
            Clear(ReminderAttachmentText);
            Clear(ReminderEmailText);
            Clear(LocalGuid);
            Clear(ReadStream);
            // Check if there are existing texts for the reminder level
            if ReminderLevels.Get(ReminderText."Reminder Terms Code", ReminderText."Reminder Level") then begin

                if not IsNullGuid(ReminderLevels."Reminder Attachment Text") then
                    LocalGuid := ReminderLevels."Reminder Attachment Text";
                if not IsNullGuid(ReminderLevels."Reminder Email Text") then
                    LocalGuid := ReminderLevels."Reminder Email Text";
                if IsNullGuid(LocalGuid) then
                    LocalGuid := CreateGuid();
                // If not then create the default ones
                if not ReminderAttachmentText.Get(LocalGuid, DefaultLanguageCode) then
                    ReminderAttachmentText.SetDefaultContentForNewLanguage(LocalGuid, DefaultLanguageCode, Enum::"Reminder Text Source Type"::"Reminder Level", ReminderLevels.SystemId);

                if not ReminderEmailText.Get(LocalGuid, DefaultLanguageCode) then
                    ReminderEmailText.SetDefaultContentForNewLanguage(LocalGuid, DefaultLanguageCode, Enum::"Reminder Text Source Type"::"Reminder Level", ReminderLevels.SystemId);
                if ReminderAttachmentText.Get(LocalGuid, DefaultLanguageCode) and ReminderEmailText.Get(LocalGuid, DefaultLanguageCode) then
                    // And then personalized them with the customer data
                    case ReminderText.Position of
                        Enum::"Reminder Text Position"::Beginning:
                            begin
                                ReminderAttachmentTextLine.Init();
                                ReminderAttachmentTextLine.Id := ReminderAttachmentText.Id;
                                ReminderAttachmentTextLine."Language Code" := ReminderAttachmentText."Language Code";
                                ReminderAttachmentTextLine.Position := ReminderAttachmentTextLine.Position::"Beginning Line";
                                ReminderAttachmentTextLine."Line No." := ReminderText."Line No.";
                                ReminderAttachmentTextLine.Text := ReminderText.Text;
                                OnBeforeInsertReminderAttachmentTextLine(ReminderText, ReminderAttachmentTextLine);
                                ReminderAttachmentTextLine.Insert(true);
                            end;
                        Enum::"Reminder Text Position"::Ending:
                            begin
                                ReminderAttachmentTextLine.Init();
                                ReminderAttachmentTextLine.Id := ReminderAttachmentText.Id;
                                ReminderAttachmentTextLine."Language Code" := ReminderAttachmentText."Language Code";
                                ReminderAttachmentTextLine.Position := ReminderAttachmentTextLine.Position::"Ending Line";
                                ReminderAttachmentTextLine."Line No." := ReminderText."Line No.";
                                ReminderAttachmentTextLine.Text := ReminderText.Text;
                                OnBeforeInsertReminderAttachmentTextLine(ReminderText, ReminderAttachmentTextLine);
                                ReminderAttachmentTextLine.Insert(true);
                            end;
                        Enum::"Reminder Text Position"::"Email Body":
                            if ReminderText."Email Text".HasValue() then begin
                                ReminderText.CalcFields("Email Text");
                                ReminderText."Email Text".CreateInStream(ReadStream);
                                ReminderEmailText.SetBodyText(TypeHelper.TryReadAsTextWithSepAndFieldErrMsg(ReadStream, TypeHelper.LFSeparator(), ReminderText.FieldName("Email Text")));
                            end;
                    end;
            end;
        until ReminderText.Next() = 0;
    end;

Internal work item: AB#623925

Metadata

Metadata

Assignees

No one assigned

    Labels

    SCMGitHub request for SCM areaevent-requestRequest for adding an event

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions