Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Business Central forum

How to apply a template to a created item?

(0) ShareShare
ReportReport
Posted on by 450

Now i've come across a C/AL code example on how to insert data through code using templates.
Now in that example first a customer (in my case item) is created and next a template is applied.

The code is as following:

// First insert a record Customer.INSERT(TRUE);

// Apply a template RecRef.GETTABLE(Customer);

ConfigTemplateMgt.UpdateRecord(ConfigTemplateHeader,RecRef);

RecRef.SETTABLE(Customer);

// Insert Dimensions – related templates

MiniDimensionsTemplate.InsertDimensionsFromTemplates(ConfigTemplateHeader,Customer."No.",DATABASE::Customer);

Now creating an empty item is pretty straight forward but once created in don't get on how i should get the item to apply a template to it.

I assume in the code example RecRef is the newly created customer but i don't know for sure.

(Also a slightly important detail, i'm coding in AL so i'm trying to convert it to that just so that there aren't any misconceptions.)

Anyone knows the solution for that?

UPDATE:

So the code i have until now is following:

Item.Insert(true);
ConfigTemplateHeader.SetRange("Table ID", 27);

if ConfigTemplateHeader.FindFirst() then begin
    RecRef.SetTable(Item);
    ConfigTemplateMgt.UpdateRecord(ConfigTemplateHeader, RecRef);

Now again, I'm just guessing that RecRef (RecordRef) is supposed to be the record i last created but i actually doubt that that is the case. So now i can insert an empty item, get the template and the way i see it update the record with the last line of code but there still remains on how to get the created record.

Categories:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans