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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

X++ How to add a tab to a form that exists through X++ Code

(1) ShareShare
ReportReport
Posted on by

Hello,

Is there a way to add tabs to a form through X++ code?

I have a form that contains 1 tab per Name that I manually create

I have a table, with 3 columns
Name       Specific Name     RecID
Name A    SpecificNameA   RecID
Name B    SpecificNameB   RecID

Right now, if I want to add Name C, I have to go into my form and manually create a new tab and set up everything that way. How I would like to have it, is where I just perform code on a class through a button, and it generates a new Tab. I have another form where I create new Names.

 7_2D00_13_2D00_2015-12_2D00_34_2D00_53-PM.jpg

I am sorry about the small size of the picture, it basically explains what I said above, 1 button to look up 1 table to generate a new tab for each line on the table using the table's names.
I am aware of Form = New Form(); code, but how does it work if the form already exists?

Thanks!

 

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    You can edit manipulate existing forms at runtime as well. This piece of code adds a new tab page to a tab control called Tab1:

    FormTabPageControl tabPage = Tab1.addControl(FormControlType::TabPage, "Tab2");
    
    tabPage.caption("Tab 2");
    tabPage.hideIfEmpty(false);
  • Community Member Profile Picture
    on at

    I was able to generate the tabs as you suggested, thank you :)

  • Community Member Profile Picture
    on at

    I just ran into another issue, how do I stop it from "continuing" to add tabs?

    If my table has 3 records, and I click my button, it will add 3, then it will add 3 more if I click it again.

    How do I avoid this? I am using a while select * myTable. Is there a way to "fail" the while select if a tabpage exists?

    For example, if I run it, and tabpage1 exists, I would like it to skip tabpage1 and go to 2 and 3. Or if it already has 2, do 1 and then 3.

    Is this possible?

  • Community Member Profile Picture
    on at

    It also keeps updating the first tabPage since I go tabPage.AddConfigurationHere();

    Is there a way for it while select and then say "TabPage1, TabPage2, TabPage3" etc?

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    You can remember tabs that you've already added, check if the tab with the same name already exists or fix your logic in some other way.

  • Community Member Profile Picture
    on at

    I was able to fix it by removing my tab pages on my form and creating it as an object.

    FormTabPageControl      tp;

    super();

       while select * From cu

       {

           s = cu.JobName;

           c = cu.Name;

           tp = Tab.addControl(FormControlType::TabPage,s);

           tp.autoDeclaration(True);

           tp.helpText(s);

           tp.widthMode(1);

           tp.heightMode(1);

           tp.caption(c);

           tp.hideIfEmpty(false);

       }

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    Please don't forget to mark the verified answer(s), if this thread is to be closed.

  • Community Member Profile Picture
    on at

    I am still having issues.

    Perhaps I am writing this wrong... I am trying to generate 2 fields from one of my data sources.

    void clicked()

    {

       FormTabPageControl     tp;

       FormGridControl         fgc;

       FormStringControl       fsc;

       str s;

       str c;

       //int id1 = fieldName2id(tableName2id("CIM_Status"), "Message");

       //int id2 = fieldName2id(tableName2id("CIM_Status"), "UtilityID");

       CIM_Utilities cu;

       super();

       while select * From cu

       {

           s = cu.JobName;

           c = cu.Name;

           tp = Tab.addControl(FormControlType::TabPage,s);

           tp.autoDeclaration(True);

           tp.helpText(s);

           tp.widthMode(1);

           tp.heightMode(1);

           tp.caption(c);

           tp.hideIfEmpty(false);

     

           fgc = tp.addControl(FormControlType::Grid,s);

           fgc.autoDeclaration(true);

           fgc.widthMode(1);

           fgc.heightmode(1);

           fgc.dataSource(tableNum(CIM_Status));

           //fgc.dataSource(CIM_Status);

     

           fsc = fgc.addControl(FormControlType::String,"CIM_TMP_Message");

           fsc.autoDeclaration(True);

           fsc.WidthMode(1);

           fsc.label("Message");

           //fsc.dataSource(CIM_Status);

           //fsc.dataField(id1);

           fsc.dataSource(tableNum(CIM_Status));

           fsc.dataField(fieldNum(CIM_Status, Message));

           fsc = fgc.addControl(FormControlType::String,"CIM_TMP_UtilityID");

           fsc.WidthMode(1);

           fsc.label("Utility ID");

           //fsc.dataSource(CIM_Status);

           //fsc.dataField(id2);

           fsc.dataSource(tableNum(CIM_Status));

           fsc.dataField(fieldNum(CIM_Status, UtilityID));

     

       }

     

    }

     

  • Community Member Profile Picture
    on at

    I made a type mistake on the 2nd field should be int64.

  • Martin Dráb Profile Picture
    237,795 Most Valuable Professional on at

    It seems to be a different topic than "How to add a tab to a form", therefore you should probably create a new thread. I also don't see any description of any problem.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans