Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How reach form datasource object in a standard method with delegate

(0) ShareShare
ReportReport
Posted on by 160

Hello,

I need to create a delegate in a standard method (use in Active standard datasource method) in order to add a specific control on datasource field:

    // Standard method where i want to use a post delegate:


    public void setFieldAccess()
    {
        boolean isResourceRate = projHourCostPrice.IsResourceRate;

        projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, Resource)).allowEdit(!isResourceRate);
        ....
    }

I create a delegate method in a specific class:

    /// <summary>
    /// Add specific control
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(formStr(ProjCostPriceHour), formMethodStr(ProjCostPriceHour, setFieldAccess))]
    public static void ProjCostPriceHour_Post_setFieldAccess(XppPrePostArgs args)
    {

        // Bad use/context  it don't work:
        FormRun                  sender = args.getThis();
        FormDataSource      projHourCostPrice_ds;
        projHourCostPrice_ds = sender.formRun().dataSource("ProjHourCostPrice");

       // I want to add this code:
        projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, Resource)).allowEdit(false);

                }

How i can reach formdatasource object with args param with delegate from a standard method in form?

*This post is locked for comments

  • Foxsor Profile Picture
    160 on at
    RE: How reach form datasource object in a standard method with delegate

    Thank's for your replies.

    @Martin yes i have made a mistake with the term, it's an handler.

    @Basheeruddin your syntax works:

           FormRun                  sender = args.getThis();

           FormDataSource      projHourCostPrice_ds;

           ProjHourCostPrice    projHourCostPrice;

           projHourCostPrice_ds = sender.dataSource(formdatasourcestr(ProjCostPriceHour, ProjHourCostPrice));

           projHourCostPrice      =  sender.dataSource(formdatasourcestr(ProjCostPriceHour, ProjHourCostPrice)).cursor();

           boolean isResourceRate = projHourCostPrice.IsResourceRate;

           projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, ResourceCategory))      .allowEdit(!isResourceRate);

           projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, ResourceCategory))      .skip(!(!isResourceRate ));

           projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, CategoryId))            .allowEdit(!isResourceRate);

           projHourCostPrice_ds.object(fieldNum(ProjHourCostPrice, CategoryId))            .skip(!(!isResourceRate));

  • Verified answer
    Basheer17 Profile Picture
    2,720 on at
    RE: How reach form datasource object in a standard method with delegate

    I think args.getThis() will return FormRun object. Because we can't create Pre/Post event handlers for datasource methods.

  • Verified answer
    Martin Dráb Profile Picture
    231,801 Most Valuable Professional on at
    RE: How reach form datasource object in a standard method with delegate

    What you're creating is a handler, not a delegate.

    Please use the debugger to see what's wrong with your code. Doesn't args.getThis() return the datasource object (instead of FormRun as expected by your code)? (Note that I'm merely guessing, because I don't have enough information about the code. The debugger will make it all clear.)

  • Suggested answer
    Basheer17 Profile Picture
    2,720 on at
    RE: How reach form datasource object in a standard method with delegate

    You can get it from formRun object.

    sender.dataSource(formdatasourcestr(ProjCostPriceHour, DATASOURCE)).cursor();

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,961 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,801 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans