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)

Create form datasource object through X++

(0) ShareShare
ReportReport
Posted on by 805

Hi

Is there any way to be created form data source through X++?

I tried something like that:

SalesQuotationLine SalesQuotationLine;

FormDataSource formDataSource = new FormDataSource();

formDataSource.table(tablenum(SalesQuotationLine));

salesQuotationLine = formDataSource.cursor();

This X++ code compiles successfully but there is a problem at runtime, because new FormDataSource() statement returns instance of an Object() class which have not table() method;

I need to pass salesQuotationLine buffer as a parameter of function and this buffer should have a valid datasource object.

Thanks.

*This post is locked for comments

I have the same question (0)
  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi Ist.

    Are you trying to pass a record from an existing datasource on the form to a different function or are you actually trying to add a datasource to a form.

    Maybe explain the business logic in a bit more detail.

  • ist Profile Picture
    805 on at

    I am trying to use a function from an existing class which accepts a table buffer (SalesQuotationLine) as parrameter. This class is used in a form which form datasource is passed as a parametter. I would like to use this class outside the form object.

    The class name is SalesQuotationTableForm_DlvSchedule method salesQuotationLine_Init().

    This is a functionality related to SalesQuotations->lines->button "sales quotation lines"->Delivery Schedules. You can see linkActive method on a form datasource.

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at

    Hi IST

    This class is used to manage and populate the SalesQuotationDeliverySchedule form. I wouldn't try and re-use this for a different form.

    However to answer your question you can pass your active form datasource to a method like this useing the data source name appended by _ds e.g. SalesQuotationline_ds

  • ist Profile Picture
    805 on at

    Hi Jonathan,

    In my case I can't.

    Thanks,

  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi Ist.

    I'm still not understanding exactly what you are trying to do. But the method you are referring to requires just the record and not a datasource, so passing simply passing the Datasource name without the _ds will work.

    As before I'd recommend you don't reuse this class for things other than what it was intended for.

  • Jonathan  Halland Profile Picture
    11,310 on at

    Hi Ist.

    I'm still not understanding exactly what you are trying to do. But the method you are referring to requires just the record and not a datasource, so passing simply passing the Datasource name without the _ds will work.

    As before I'd recommend you don't reuse this class for things other than what it was intended for.

  • Suggested answer
    Maqk Profile Picture
    844 on at

    If you want to add a DataSource at runtime to a form having no DataSource defined in design, check below links

    msdn.microsoft.com/.../formrun.datasource.aspx

    dynamicsuser.net/.../420146.aspx

    The theme in above links is to create the whole Form at runtime. But the code that adds the DataSources into form is usable in your scenario

    The other way to achieve your requirement would be to add a DataSource to your Form at designtime and bind it with Common (Table's base class). This is common practice in AX. Then before the super call of init(), initialize the Common DataSource providing it with new table that you want it to bind to.

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi

    I do understand the reason for your question, as I needed to build a similar solution.
    A lot of functionality in AX is initiated from a form-button, where a filter on a data-source is the key for selection in that subsequent process.

    If you now want to simulate that process without the interference of a form (user), the subsequent process still requests a form-data-source.

    My solution is based on several sources, and tweaked a bit:    (I need to post a wmsShipment record autonomous)

    void postShipment(WMSShipment _wmsShipment)
    {
        Args                       args = new Args();

        Form                            frm;
        FormBuildDesign         fbd;
        FormRun                      fr;

        FormBuildDataSource  fbds;
        FormDataSource          fds;

        QueryBuildDataSource    qbds;
        QueryBuildRange            qbr;


        wmsShipmentOption       wmsShipmentOption = new wmsShipmentOption();
    ;

        // Construct a form
        frm = new Form();

        fbds = frm.addDataSource(_wmsShipment.name);
        fbds.table(_wmsShipment.TableId);
        fbd = frm.addDesign("Design");

        args.object(frm);

        // Run just some parts of the form, in order to have the form-data-source available afterwards
        fr = new FormRun(args);
        fr.init();

        // Setting the query filter to just one record I want to pass
        fds  = fr.dataSource(1);
        qbds = fds.query().dataSourceNo(1);
        qbr  = qbds.addRange(FieldName2Id(_wmsShipment.TableId, "ShipmentId"));
        qbr.value(_wmsShipment.shipmentId);

        fds.executeQuery();


        // This can be skipped, as we actually rather not have this form show on screen
        // fr.run();
        // fr.detach();


        // retrieve that dataSource with just that single record.
        fds = fr.dataSource(1);
        _wmsShipment = fds.getFirst();
        

        // All preparations done:
        // Now run the PackingSlip software
        wmsShipmentOption.parmPackAllQuantitiesAndPrint(true);


        args.record(_wmsShipment);
        args.caller(fr);
        args.parmObject(wmsShipmentOption);

        new MenuFunction(menuitemactionstr(SalesFormLetter_PackingSlip), MenuItemType::Action).run(args);


        // Don't forget to clean-up the form, although it hasn't been shown on screen.
        fr.close();
    }

    Hope this helps.

    Bert

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

    Your code won't work in your scenario, i.e. in a web service. Web services runs on AOS without client, but FormRun class can run only on client and therefore it can't be used from web services.

    The same applies in other cases where there is no client process, such as in batch.

  • Community Member Profile Picture
    on at

    Hi Martin,

    True.  I've removed the 'webservice' part of it in my post.   Still in my particular situation it works fine.

    Thanks for the sharp eye.  ;)

    Bert

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