web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

Installing data conditionally from Install codeunit

(0) ShareShare
ReportReport
Posted on by 120

Hi All,

I'm trying to install extension with with initial setup data. I want to insert setup data only for a specific company. This seems possible by conditionally checking 'CompanyName'.

codeunit 50140 "Install codeunit"
{
    Subtype = Install;

    // trigger OnInstallAppPerDatabase()
    // begin
    //     AddMessageToOurTable('OnInstallAppPerDatabase');
    // end;

    trigger OnInstallAppPerCompany()
    begin
        if CompanyName() = 'CRONUS AU' then begin
            //record insert code here
        end;
    end;
}

Is that possible to add hard coded value 'CRONUS AU' with user input?

or is there any other way to add some data only for a selected company with extension installation process?

Appreciate your advice.

Thanks,

  • YUN ZHU Profile Picture
    103,829 Super User 2026 Season 2 on at

    Hi, although I haven't tested it yet, I think you can use ChangeCompany Method before inserting setup data.

    https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/methods-auto/recordref/recordref-changecompany-method

  • Nalin.karu Profile Picture
    120 on at

    Hi Yun,

    Thanks for your reply.

    It's not possible with RecordRef.ChangeCompany(). let me explain my question further, as I feel I haven't asked my question clear.

    As I understood, when OnInstallAppPerCompany() trigger executing, it repeat through company list. As in the above code sample, we can conditionally check the company name before to execute code within the trigger. but the company name is hard coded. Is it possible get this value as a user input (like from a standard dialog box) from client?

    Nalin.
  • YUN ZHU Profile Picture
    103,829 Super User 2026 Season 2 on at

    Hi, I’m sorry I didn’t fully understand it before. 

    Yes, when installing the extension, the standard dialog box for user input cannot be used.

    So does the following solution meet the needs? You can get the company name for a specific user from the table User Personalization (2000000073). For example, 'Admin'.

    I tested the following program, which only modifies the data of one company.

    pastedimage1622794825809v1.png

    pastedimage1622794851439v2.png

  • Verified answer
    Nalin.karu Profile Picture
    120 on at

    Hi Yun,

    Thanks for your quick reply and valuable suggestion. definitely I was looking for this kind of solution.

    Thanks,

    Nalin.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 728 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 545 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 328 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans