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

Could not process the lookupRecord value on the Args instance

(1) ShareShare
ReportReport
Posted on by 1,965
Hi,

I'm getting this error:

Could not process the lookupRecord value on the Args instance. The table 'Table2' does not exist as a root FormDataSource for the form 'SalesTable__SalesLine_CodeXRecId'
 
Public class CodeXEventHandlers
{

     FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]
    public static void SalesLine_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)
    {

            var overrides = SalesTableFormExtensionOverrides::construct();

            sender.object(fieldNum(SalesLine, CodeXRecId)).registerOverrideMethod(methodStr(FormReferenceControl, lookupReference)
            , methodStr(SalesTableFormExtensionOverrides, overridenCodeXRecIdLookup), overrides);

    }

}
 

public class SalesTableFormExtensionOverrides
{
    protected void new()
    {
    }

    public static SalesTableFormExtensionOverrides construct()
    {
        return new SalesTableFormExtensionOverrides();
    }




    public Common overridenCodeXRecIdLookup(FormReferenceControl _formControl)
    {
        Common                      commonRecord;
        View1                        selectedRecord;

        SysReferenceTableLookup sysTableLookup = SysReferenceTableLookup::newParameters(tableNum(View1), _formControl);
       
        FormRun         formRun         = _formControl.formRun();
        FormDataSource  salesLine_ds    = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine));
        SalesLine       salesLine       = salesLine_ds.cursor();
        Query           query           = new Query();
               
        QueryBuildDataSource qbds = query.addDataSource(tableNum(View1));


        if(salesLine.ItemId)
        {
            qbds.addRange(fieldNum(View1, ProductCodeY)).value(queryValue(salesLine.ItemId));
        }
        if(salesLine.Id)
        {
            qbds.addRange(fieldNum(View1, Id)).value(queryValue(salesLine.bId));
        }

        QueryBuildDataSource inventTableDataSource = qbds.addDataSource(tableNum(InventTable));
        inventTableDataSource.relations(false);
        inventTableDataSource.addLink(fieldNum(View1, CodeY),fieldNum(InventTable, ItemId));
        inventTableDataSource.joinMode(JoinMode::InnerJoin);
        inventTableDataSource.addRange(fieldNum(InventTable, DataAreaId)).value(queryValue(salesLine.DataAreaId));

        sysTableLookup.addLookupfield(fieldNum(View1, CodeY));
        sysTableLookup.addLookupfield(fieldNum(View1, Name));
        sysTableLookup.addLookupfield(fieldNum(View1, Field1));

        sysTableLookup.parmQuery(query);
        commonRecord = sysTableLookup.performFormLookup();
        if (commonRecord.RecId)
        {
            selectedRecord = commonRecord;
        }

        return selectedRecord;

    }

}

Note: View1 has Table2 inner join table1

Existing relations on tables:
Table2.Id == Table1.Id

SalesLine.CodeXRecId == Table2.RecId
Categories:
I have the same question (0)
  • Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at
    I guess that you're returning a wrong table, e.g. that you have a lookup for Table2 and you're returning View1 instead. Use the debugger to see what your code does at runtime.
  • .. Profile Picture
    1,965 on at
    Hi Martin,

    I can't tell what's wrong, when i debug, commonRecord shows "no data selected"

    I need the view because i'm showing fields from different tables, not sure what to do instead
  • Suggested answer
    Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at
    There are surely things you could find out. For example, where is the error thrown from? If performFormLookup() returns a value, what is the data type?
     
    Anyway, if CodeXRecId has a relation to Table2.RecId, you lookup must return Table2. That you're returning View1 instead is a bug and a reason for the error.
  • .. Profile Picture
    1,965 on at
    Hi Martin,

    How i'm going to return Table2? what to amend in my code?
    My view contains Table2 joined with Table1. And i need the view, because the field name exists in Table1 and not Table2 and i need to show it in the lookup
    sysTableLookup.addLookupfield(fieldNum(View1, Name));


    the error appears when calling performFormLookup.
    here exactly

  • Suggested answer
    Martin Dráb Profile Picture
    237,805 Most Valuable Professional on at
    You need Table2. You can, for example, get View1 from performFormLookup(), find the corresponding Table2 record and return it from overridenCodeXRecIdLookup().
     
    Or you could stop using View1, because you're wrong in thinking that there is no solution without a view. You could write a display method on Table2 and add it to the lookup via addLookupMethod().
  • .. Profile Picture
    1,965 on at
    Hi Martin,

    Yes i already solved it by adding the other field as display method.

    But if i kept using the view, how would i return table2 from it? you mean do another select to get the table by relating it to the view?

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

#1
Martin Dráb Profile Picture

Martin Dráb 664 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 522 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 303 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans