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

set cursor on form datasource upon form opening

(0) ShareShare
ReportReport
Posted on by 942

Hello,

I have a datasource on the form which is not joined to any other datasource. I'd like to set a cursor on particular record upon form opening. How can I do this? I tried to do the following in init and executequery methods of the form datasoiurce extension but this is not working. However range works fine and I can the value in projid field on the form but when I try to update any field form this record. IN projTable validatewrite() method projtable record is empty which means I don't have cursor set up on the datasource

[ExtensionOf(FormDataSourceStr(ProjValSetupEmplProj, ProjectTable))]
internal final class BWProjValSetupEmplProjProjectTableDS_Extension
{
    

    void init()
    {
        next init();

        if (element.args().dataset() == tableNum(ProjTable))
        {
            QueryBuildDataSource qbdsProjectTable;
            ProjTable projTable = element.args().record();

            qbdsProjectTable = this.querybuilddatasource();
            qbdsProjectTable.addRange(fieldNum(ProjTable,ProjID)).value(queryValue(projTable.projid));
            
            //this.cursor(projTable);
            //this.findrecord(projTable);

        }    
    }

    public void executeQuery()
    {
        ProjTable projTable = element.args().record();
        this.findrecord(projTable);
        next executeQuery();
    }

I have the same question (0)
  • GirishS Profile Picture
    27,827 Moderator on at

    Hi Azat,

    Try using positionToRecord method in form datasource.

    Thanks,

    Girish S.

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

    Both places are wrong.

    In init(), the query hasn't been executed yet.

    In executeQuery(), you would find the record and then execute the query, effectively destroying what you just did. Also, it would happen every time when the query gets executed, not just when opening the form, which is what you wanted.

    A good place may be the run() method, below next run().

  • dark_knight Profile Picture
    942 on at

    I already solved my problem but according o this

    learn.microsoft.com/.../event-method-sequences-when-a-form-is-opened

    run() of the form  is called before init() and executeQuery() of the datasource. It seems run() is also not a good choice

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

    No, run() isn't called before init() and the documentation page doesn't claim that.

    You're probably confused by the fact that the table shows ds.init() (thread 2) below Form.run() (thread 1), but it doesn't mean a sequence in which they're executed

    The fact that you can't run a form before creating data sources and controls should make sense.

  • dark_knight Profile Picture
    942 on at

    Thanks Martin

  • AprilC Profile Picture
    on at

    I tested the order should be:

    Form.init()

    FormDataSource.init()

    Form.run()

    FormDataSource.executeQuery()

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans