ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

[Event Request] Codeunit 8612 "Config. Template Management" - Function "InsertTemplate" - Add event OnAfterInsertTemplate

Open ROUCHY-Yoann opened this issue 2 years ago • 8 comments

Describe the request

Hello, can you please add a new Event "OnAfterInsertTemplate" in codeunit 8612 "Config. Template Management" - Function "InsertTemplate" ?

procedure InsertTemplate(var RecRef: RecordRef; ConfigTemplateHeader: Record "Config. Template Header"; SkipFields: Boolean; var TempSkipField: Record "Field")
var
    ConfigTemplateLine: Record "Config. Template Line";
    ConfigTemplateHeader2: Record "Config. Template Header";
    FieldRef: FieldRef;
    RecRef2: RecordRef;
    SkipCurrentField: Boolean;
begin
    OnBeforeInsertTemplate(ConfigTemplateLine, ConfigTemplateHeader);
    ConfigTemplateLine.SetRange("Data Template Code", ConfigTemplateHeader.Code);
    if ConfigTemplateLine.FindSet() then
        repeat
            case ConfigTemplateLine.Type of
                ConfigTemplateLine.Type::Field:
                    if ConfigTemplateLine."Field ID" <> 0 then begin
                        if SkipFields then
                            SkipCurrentField := ShouldSkipField(TempSkipField, ConfigTemplateLine."Field ID", ConfigTemplateLine."Table ID")
                        else
                            SkipCurrentField := false;

                        if not SkipCurrentField then begin
                            FieldRef := RecRef.Field(ConfigTemplateLine."Field ID");
                            ModifyRecordWithField(RecRef, FieldRef, ConfigTemplateLine);
                        end;
                    end;
                ConfigTemplateLine.Type::Template:
                    if ConfigTemplateLine."Template Code" <> '' then
                        if ConfigTemplateHeader2.Get(ConfigTemplateLine."Template Code") then
                            if ConfigTemplateHeader2."Table ID" = ConfigTemplateHeader."Table ID" then
                                InsertTemplate(RecRef, ConfigTemplateHeader2, SkipFields, TempSkipField)
                            else begin
                                UpdatingRelatedTable := true;
                                RecRef2.Open(ConfigTemplateHeader2."Table ID");
                                UpdateRecord(ConfigTemplateHeader2, RecRef2);
                                UpdatingRelatedTable := false;
                            end;
                else
                    OnInsertTemplateCaseElse(ConfigTemplateLine, ConfigTemplateHeader2, FieldRef, RecRef2, SkipFields, TempSkipField, RecRef);
            end;

        OnAfterInsertTemplate(ConfigTemplateLine, ConfigTemplateHeader2, FieldRef, RecRef2, SkipFields, TempSkipField, RecRef);

        until ConfigTemplateLine.Next() = 0;
end;

[IntegrationEvent(false, false)] local procedure OnAfterInsertTemplate(var ConfigTemplateLine: Record "Config. Template Line"; var ConfigTemplateHeader: Record "Config. Template Header"; FldRef: FieldRef; var RecRef: RecordRef; SkipFields: Boolean; var TempSkipField: record Field; OldRecRef: RecordRef) begin end;

Additional context

We have to add values to "RecRef" after each loop and whatever the ???Type??? of the case. Internal work item: AB#554361

ROUCHY-Yoann avatar Oct 09 '24 09:10 ROUCHY-Yoann

@ROUCHY-Yoann sorry, this fell through the cracks. Can you confirm this is something you still need before I assign an engineer to look into the issue?

Aleyenda avatar Apr 10 '25 09:04 Aleyenda

Hello, Yes, i confirm i still need this demand. Thank you

ROUCHY-Yoann avatar Apr 10 '25 09:04 ROUCHY-Yoann

@ROUCHY-Yoann , thanks for getting back to us.

Can you further elaborate on the scenarios here? I can see the RecRef is the record you want to update using the Template here, so I'm not sure I understand why you want to add values to "RecRef" after each loop

haoranpb avatar Apr 14 '25 13:04 haoranpb

In the case where the “name” of “RefRef” is equal to “ITEM”, we want to modify the value of a custom field. We created a custom field in the 50000.. range.

By adding this new event, we can be sure that we'll be able to check the table used in “RecRef” at each loop, and thus modify the custom field. No matter what standard code is added to this function.

Am I making myself clear?

ROUCHY-Yoann avatar Apr 14 '25 14:04 ROUCHY-Yoann

As far as I can see, the described scenario can be achieved without the event:

For example, in app Subscription Billing: A customized field is added to Item table: https://github.com/microsoft/ALAppExtensions/blob/09e4b4bd7c6dc81d29ac3150907235467accaadc/Apps/W1/SubscriptionBilling/App/Service%20Objects/Table%20Extensions/Item.TableExt.al#L19

Item Template is then further extended to populate the field using Item Template feature: https://github.com/microsoft/ALAppExtensions/blob/09e4b4bd7c6dc81d29ac3150907235467accaadc/Apps/W1/SubscriptionBilling/App/Service%20Objects/Table%20Extensions/ItemTempl.TableExt.al#L9

Please let me know if I mis-understood anything, I will be closing this issue for now.

haoranpb avatar Apr 15 '25 11:04 haoranpb

So, i must install a new extension not needed by my customer (Subscription Billing App), to manage this field ?

ROUCHY-Yoann avatar Apr 15 '25 12:04 ROUCHY-Yoann

I think you mis-understood my comment...

Above code from Subscription Billing is just an example of how to achieve what you want without using an event.

haoranpb avatar Apr 15 '25 12:04 haoranpb

Ok, thank you. I'll try.

ROUCHY-Yoann avatar Apr 15 '25 12:04 ROUCHY-Yoann