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 :
Finance | Project Operations, Human Resources, ...
Answered

Unable to cast object of type 'Dynamics.AX.Application.FormStringControl' to type error

(1) ShareShare
ReportReport
Posted on by 203
Hi,
I am trying to have a lookup for line numbers in a custom table by writing the code in event handler but getting this error -'Unable to cast object of type 'Dynamics.AX.Application.FormStringControl' to type 'Dynamics.AX.Application.FormReference'. What can be resolution for the same.
 [FormControlEventHandler(formControlStr(A, B), FormControlEventType::Lookup)]
    public static void B_LineNumber_OnLookup(FormControl sender, FormControlEventArgs e)
    {
        SysReferenceTableLookup tableLookup = SysReferenceTableLookup::newParameters(tableNum(X), sender);

        FormRun formRun =  sender.formRun();

        Query query = new Query();


        QueryBuildDataSource         qbds             = query.addDataSource(tableNum(X));          
        A                            solTable         = sender.formRun().dataSource(formDataSourceStr(A, B)).cursor();

        qbds.addRange(fieldNum(X, SolutionId)).value(solTable.SolutionId);

        tableLookup.parmQuery(query);
        tableLookup.addLookupfield(fieldNum(X, LineNumber));
        tableLookup.addLookupfield(fieldNum(X, SolutionId));

        tableLookup.performFormLookup();

        FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
        ce.CancelSuperCall();

       
    }
Please note I am getting an error at SysReferenceTableLookup line. I belive its because its fetching the recId but I want a string. Kindly let me know how may I tackle this error.
I have the same question (0)
  • Verified answer
    Layan Jwei Profile Picture
    8,165 Super User 2026 Season 1 on at
    Hi,

    So you have form 'A' with control 'B'.  What's the type of control 'B'? is it string?
    Why you are not using SysTableLookup instead of SysReferenceTableLookup?

    And I'm confused, which table do you want to use. Sometimes you put X, sometimes you put B and sometimes you put A?

    I assume you want X

    maybe you meant the code to be like this? (just trying to re-write it quickly)
    [FormControlEventHandler(formControlStr(A, B), FormControlEventType::Lookup)] //here it means form A control B
    public static void B_LineNumber_OnLookup(FormControl sender, FormControlEventArgs e)
        {
            SysTableLookup tableLookup = SysTableLookup::newParameters(tableNum(X), sender);// I replaced SysReferenceTableLookup with SysTableLookup 
    
            FormRun formRun =  sender.formRun();
    
            Query query = new Query();
    
    
            QueryBuildDataSource         qbds           = query.addDataSource(tableNum(X));          
            X                            xTable         = formRun .dataSource(formDataSourceStr(A, X)).cursor(); //A is form so solTable should be of TypeX and not A and formDataSource should contain X and not B
    
            qbds.addRange(fieldNum(X, SolutionId)).value(xTable.SolutionId);
    
            tableLookup.parmQuery(query);
            tableLookup.addLookupfield(fieldNum(X, LineNumber));
            tableLookup.addLookupfield(fieldNum(X, SolutionId));
    
            tableLookup.performFormLookup();
    
            FormControlCancelableSuperEventArgs ce = e as FormControlCancelableSuperEventArgs;
            ce.CancelSuperCall();
    
           
        }
    ​​​​​​​

    Thanks,
    Layan Jweihan
    ​​​​​​​Please mark this answer as "Verified" if it solved your issue. In order to help others who will face a similar issue in the future
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Please share us the exact code since we are not able to understand what is being used in the lookup as a table and also if you need a recid or string since you are using SysTableReferenceTableLookup. Also please give us more information on the business requirement.
  • spidey1010 Profile Picture
    203 on at
    HI Layan,
    Thanks for the response, SysTableLookup solved my 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

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 689

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 455 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 308 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans