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, ...
Suggested Answer

Not Getting data source from formrun.datasource()

(0) ShareShare
ReportReport
Posted on by 4

hello everyone,

I am not getting data source from below code that  when I am passing record from args.

can anyone help me out with this that how can i get data source from form run;

args.record(whsWorkLineCyclecountLoc);


args.name("WHSWorkLineCycleCount");


formRun = classFactory.formRunClass(args);

 whsWorkLineCyclecountfds = formRun.dataSource("WHSWorkLineCycleCount");

I have the same question (0)
  • Gunjan Bhattachayya Profile Picture
    35,423 on at

    Hi Siddy,

    Where are you passing the args from? You can pass the form control value into the args and retrieve the formRun. 

    Your code for obtaining the data source is correct.

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    What are you trying to do here?

    Are you trying to start a new form from x++ code? At least that's what the code looks like. But your code hasn't yet run the init method of the form, therefore the data source is not initialized.

    Or, are you trying to get data source of a caller form? If yes, your code is not correct.

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

    Also, you seem to believe that the record you pass in Args will be set to a data source. That's not the case. If there is a relation (or code in the form doing the same thing), the record will be used to filter the data source. Otherwise it won't have any effect at all.

  • WillWU Profile Picture
    22,361 on at

    Hi Siddy Mujumdar,

    As Nikolaos said ,If you want to use the Args object to create a form, you have to run the init() method.

    Args    args = new Args(yourform);
    args.caller(yourform)
    args.record(yourdatasource);
    FormRun formRun = ClassFactory.formRunClass(args);
    formRun.init();

  • Siddy Mujumdar Profile Picture
    4 on at

    No, Nikolas i am not trying to create a new form i just want to get data source of a  that table or caller form

  • WillWU Profile Picture
    22,361 on at

    Hi Siddy Mujumdar,

    Could you please provide the complete code?

    Even if you're not creating the form, it makes no sense if you didn't call the init() method.

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at

    You can get the data source of the caller record by args.record().dataSource();

    And you can access any controls, methods etc on the caller form via args.caller() which returns the FormRun of the caller form.

    This is of course assuming that you have passed the caller form in the args. If you used a MenuItemButton and set data source to it, then the caller and the record have been passed automatically. If you created the args manually in the calling end, you have to pass these values to it.

  • Siddy Mujumdar Profile Picture
    4 on at

    I don't want to call form i just want create data source of WHSWorkLineCycleCount on button click

  • nmaenpaa Profile Picture
    101,160 Moderator on at

    Do you mean that you want to add a new data source to an existing form?

    Or do you mean that you want to add a new record to existing data source on this form?

    Could you please try to share your actual full business requirement in as clear terms and as much detail as possible? This will save your time and ours. Thanks!

    And please share your full code as already requested.

  • WillWU Profile Picture
    22,361 on at

    Hi Siddy Mujumdar,

    Please tell us clearly about your business requirements.

    If you want to retrieve the table buffer, you can try:

    WHSWorkLineCycleCount wHSWorkLineCycleCount;
    
    select firstOnly WHSWorkLineCycleCount;
    
    args.record(wHSWorkLineCycleCount);

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans