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 :
Microsoft Dynamics AX (Archived)

X++ Generated Tabs not returning values

(0) ShareShare
ReportReport
Posted on by
Hello,

I am trying to add a new tabpage on my form for each field I have on a table I created. So far I have 2 records on the table, and I generate 2 tabs. However, I have another class that fills the tabs with data. When I manually create these tabs, the form works. I also have a query on the CIM_Status datasource that should make tab 1 show different records than tab 2 even though they are from the same source.

The reason I wish to do this, is so that if I want to update this form, the only code I need to update is the class that generates the values.

I can get this form to work fine if I manually do everything, but would like it to generate values in the fields I created.

Here is my code:


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::Int64,"CIM_TMP_UtilityID");
        fsc.autoDeclaration(True); 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)); } }


*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    You showed some code, but it's not clear what problem you have with it.

    I also don't understand how you want to achieve that "tab 1 show different records than tab 2 even though they are from the same source". If they share the same datasource, they should display the same data, shouldn't they?

  • Community Member Profile Picture
    on at
    public void init()
    {
    
        super();
        QCIM_Status = this.Query().dataSourceName('CIM_Status').addRange(fieldNum(CIM_Status,UtilityID));
    }
    
    public void executeQuery(String255 _jobName="")
    {
        select firstOnly RecId from CIM_Utilities
        where CIM_Utilities.JobName == _jobName;
    
        QCIM_Status.Value(queryValue(CIM_Utilities.RecId));
        super();
    }
    
    public void tabChanged(int _FromTab, int _ToTab)
    {
        CIM_Utilities   cu;
        //Tabs start at 1
    
        super(_FromTab, _ToTab);
        if(_ToTab == 1)
        {
            element.lock();
            CIM_Status_DS.executeQuery("OrphanedAXUserOrGroup");
            element.unLock();
        }
        if(_ToTab == 2)
        {
            element.lock();
            CIM_Status_DS.executeQuery("FindAXUsersDisabledInAD");
            element.unLock();
        }
        return;
    }
  • Community Member Profile Picture
    on at

    I apply a range on the datasource execute query. The one table gets populated by a tmp table, but it has 1 utility ID per utility run, so if I have 2 utilities, it will say recid1 for Utility 1 and recid2 for Utility 2. Even though the table has both values in it, it separates the data per tab with the "tab changed" method.

  • Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    In other words, you change the query when switching tabs.

    By the way, if all tabs have the same set of fields, you can implement the same with with a single tab and a single filter field.

  • Community Member Profile Picture
    on at

    The point of the form is to run a bunch of job scripts to return different levels of error.

    So let's say I have 10 users who aren't in our active directory, it would check off the "isError, isWarning, and isInfo" check box on the main table. This is the table that drives how many tabs show up. 0-4 is info, 5-9 is warning, and 10+ is Error. The tabs separate each list by it's specific job. Maybe there is a fancier way of separating the jobs and still have them easily found.

    The only hiccup for this not working as designed is the fields being generated with X++ not being populated. I believe the reason for this, is that the datasource and datafield are not being properly populated. I am not sure what code would go there to make it say "CIM_Status" and "Message" or "UtilityID", since hard coding doesn't work (it keeps saying "Left"??? in the debugger), and trying to use tablenum or fieldnum also doesn't seem to work.

    Thoughts?

  • Suggested answer
    Martin Dráb Profile Picture
    239,040 Most Valuable Professional on at

    Then all you need is an enum filter with three values (Info, Warning and Error), to build the tab at design time and to throw away all code except filtering by severity (one line of code).

    Don't make it more complicated than necessary, especially if you aren't able to develop the complicated design.

  • Community Member Profile Picture
    on at

    I have the three values figured out... That wasn't the hard part. Like I said, the form works if I create everything manually. Where it fails, is that it won't generate the data on the code-generated design. I would get not making things more complicated than they need to be, but since it isn't very clear why it isn't working that is what I am more interested in.

    I'll have to re-design the automatic side of it... Since I don't believe that this will work as intended. It might be simplest to just do it manually.

  • Verified answer
    Douglas Noel Profile Picture
    3,905 on at

    Hi Michael,

    this WILL NOT WORK.

    Problem is using the tablenum for DataSource

    you HAVE to use the ID of the FormDataSource instead. This will work like a chaeme.

    simple example

    void clicked()
    {
        FormComboBoxControl fcbc;
        ;
        super();
        // 1st way using staamdard formcontrols and setting properties
        fcbc = (grpMain.addControl(FormControlType::ComboBox, 'Test') ) as FormComboBoxControl;
        fcbc.dataSource(InventTable_DS.id());
        fcbc.dataField(fieldNum(InventTable, ItemType));
        // 2nd way add as datafield
        grpMain.addDataField(InventTable_DS.id(), fieldNum(InventTable, ItemType));
    }


    regards

    Douglas

  • Community Member Profile Picture
    on at

    This worked!

    Thank you so much!

    Now I will be able to continue with my form as intended, this is very helpful thank you.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans