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, ...
Answered

queryrun() method in form extension is returning null value

(0) ShareShare
ReportReport
Posted on by 942

Hello,

IN extension of the standard form HCMWorkLookup I'm trying to update query  like that

if (this.args().parm() == "TORFCTABLE")// && this.args().caller() && this.args().caller().name() == classStr(TOR_FCTableReport_UNI))
{
    QueryRun qr;

    hcmWorkerLookup.parmIncludeOnlyCurrentLegalEntity(true);

    LegalEntityRange.visible(false);

    qr = this.HcmWorker_ds.queryRun();
    qr = HcmWorker_ds.queryRun();
    
    HcmWorker_ds.queryRun().query(hcmWorkerLookup.updateQuery());
}

While executing line12 I get an error

System.NullReferenceException: 'Object reference not set to an instance of an object.'

I checked qr above this line 12 and they return null.

hcmWorkerLookup.updateQuery() return query correctly.

This code actually exists on the original HCmWorkerLookup form

HcmWorker_ds.queryRun().query(hcmWorkerLookup.updateQuery());

and doesn't cause any issues. Maybe I'm missing something?

Thanks.

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

    From where are you calling your code?

  • dark_knight Profile Picture
    942 on at

    From form extension

    [ExtensionOf(formStr(HcmWorkerLookup))]
    final class HcmWorkerLookupFormUni_Extension 
    {
        void init()
        {    
            QueryBuildDataSource    qbds, qbds2;
            QueryBuildRange         qbr;
    
            next init();
    
            
            if (this.args().parm() == "TORFCTABLE")// && this.args().caller() && this.args().caller().name() == classStr(TOR_FCTableReport_UNI))
            {
                QueryRun qr;
    
                hcmWorkerLookup.parmIncludeOnlyCurrentLegalEntity(true);
    
                LegalEntityRange.visible(false);
    
                qr = this.HcmWorker_ds.queryRun();
                qr = HcmWorker_ds.queryRun();
                
                //this.HcmWorker_ds.queryRun().query(hcmWorkerLookup.updateQuery());
                HcmWorker_ds.queryRun().query(hcmWorkerLookup.updateQuery());
                //this.HcmWorker_ds.executeQuery();
            }
            
        }

  • Suggested answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Trying to run the query during in init() is both unnessary and wrong. Forget both queryRun() and executeQuery() - just modify the query returned by HcmWorker_ds.query() and let the system run executeQuery() method automatically at the right time.

  • dark_knight Profile Picture
    942 on at

    I copied this code from standard HCmWorkerLookup form. It's selectionchange() method

        [Control("ComboBox")]
        class LegalEntityRange
        {
            public int selectionChange()
            {
                int ret;
    
                ret = super();
    
                hcmWorkerLookup.parmIncludeOnlyCurrentLegalEntity(this.selection() == HcmLegalEntityRange::CurrentLegalEntity);
    
                HcmWorker_DS.queryRun().query(hcmWorkerLookup.updateQuery());
                hcmWorker_ds.executeQuery();
    
                return ret;
            }
    
        }

    Here they change the query itself and it works. 

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

    Yes, but that's a different thing. You're calling your code when the form is being initialized and no QueryRun object has been created yet.

    The standard code runs when user changes a value of a control, which can only happen after the form was fully initialized (and it was actually executed).

  • dark_knight Profile Picture
    942 on at

    But I call it after next init() which in turn calls init() methods of other datasources. Doesn't it mean that the form is already initialized?

  • Verified answer
    Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    No, it doesn't mean that the form was already executed QueryRun was objects created. Your current problem is a proof.

    And there is no point in explicitly calling executeQuery(), because it's called automatically when opening the form, as I mentioned. Put a breakpoint there and run the form to see it for yourself.

  • dark_knight Profile Picture
    942 on at

    OK. Thank you. I'll deal with it further by myself:)

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 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans