Skip to main content

Notifications

Small and medium business | Business Central, N...
Answered

Fields on page based on opened company

Posted on by 431

Hi All,

I have a request to have one page that displays fields based on users' opened company.
Page ID 30 - Item Card

field number: 50000 - ABC -> has to be displayed for user that is logged into the Company A, while user that is logged into the company B must not see that field.

So far, I have managed to write  the code to check for current opened company of user, but I am stucked on displaying fields based on users' currently opened (logged) company.

CU1 - Application Management
local procedure=isCountryB

On the Page ID 30 - Item Card
Global Variable=AppMgt | Codeunit | Application Management

CODE:
OnOpenPage
IF AppMgt.IsCountryB THEN
   ABC :=TRUE; -> this does not work as expected, field is displayed anyway to any user that opens any company

Do you have any idea on best possible solution? I once created a copy of the page on company (original company) and then added it into the menu of company (B - additional company) for which this page is intended to be used, so that user would open that page under the (B - additional) company only, and if same user would open different (original) company, then it would have only an original page.

 Thanks, Damjan

  • Damjan Zakojc Profile Picture
    Damjan Zakojc 431 on at
    RE: Fields on page based on opened company

    Hi,

    I sorted this out with combination of Lars suggestion and my own.

    Code:

    Page ID 30

    OnInit trigger

    IF AppMgt.IsCountryB THEN

      MyIsVisible := TRUE;

    This checks currently opened company of user and displays field based on condition of boolean MyIsVisble and that is added on property: Visible of field on Page ID 30.

    This AppMgt.IsCountryB will now be also used to apply the code as local specific of the country. (If country USA do this, else do that).

    On T72 - Company information new field is added - Country as an option data type where all countries are inserted that represents country where company is registered.

    I will not write core code that applies to all countries (companies) and local specific code that will be applied only to the users' currently opened company.

    Thanks, Damjan

  • Suggested answer
    Damjan Zakojc Profile Picture
    Damjan Zakojc 431 on at
    RE: Fields on page based on opened company

    Hi Lars,

    this is one possible solution, not bad either.

    I just don't like that company is hardcoded.

    Thanks, Damjan

  • Damjan Zakojc Profile Picture
    Damjan Zakojc 431 on at
    RE: Fields on page based on opened company

    Hi Duilio,

    I have to create "hardcoded company" because I will need to write code to be valid only for company B, or C, or A, not not for all companies inside the database.

    I do not know of any other solution, then that one.

    And since I will have to do this, I wanted to use also this to display or hide fields based on currently opened company of the user.

    If visibility management codeunit is something that would ease my work and ease the support I would be glad to use it, but I do not know it. I have always used so called "hardcoded company" as you are referring it.

    Thanks, Damjan

  • Verified answer
    RE: Fields on page based on opened company

    Hi,

    I guess you have thought of just using the system variable COMPANYNAME? So on the page set propery Visible to MyIsVisible, which is a new Boolean Variable, and then set it on Init of the page:

    OnInit()

    MyIsVisible := COMPANYNAME = 'ABC';

  • Suggested answer
    THE Italian Profile Picture
    THE Italian on at
    RE: Fields on page based on opened company

    Hardcoding the company is something I dislike (brrr).

    Given these constraint and if you do not want to spend time in considering to create a visibility management codeunit, I guess that you could create different groups in the card page and in each group you add the fields that you want to display per company.

    Then you use the same boolean value to trigger visible true/false in these groups.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans