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 :
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

I have the same question (0)
  • Suggested answer
    Basheer17 Profile Picture
    2,720 on at

    You can get it from formRun object.

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

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

    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.)

  • Verified answer
    Basheer17 Profile Picture
    2,720 on at

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

  • Foxsor Profile Picture
    160 on at

    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));

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans