web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to get field value from form through X++

(0) ShareShare
ReportReport
Posted on by 5

I have some doubts on this topic. How can I make my variable have the same value as the value in a form field?

Form has a field that consists of a drop down menu (lookup) in order to select one possible name. I am creating a class and one of the variables has to have the same value as the value present in that form. How can I access the form and say, for example:

string myVariable = formVariable;

EDIT:

To clarify, for example, I choose the name Julius Ellis on the form field.

In the external class (not connected to the form), I want to say that string myVariable must have the name Julius Ellis. If I then change the form field to Kendall Baptiste, the variable should now have the name Kendall Baptiste.

I have the same question (0)
  • Ranjeet_Kr Profile Picture
    on at
    RE: How to get field value from form through X++

    Requirement is quite different, never came across this scenario before.

    May be you can consider focusing the logic at DB level than form level.

  • Julius Ellis Profile Picture
    5 on at
    RE: How to get field value from form through X++

    I'm not sure how to answer that.. I don't understand..

    I understand I'm selecting one record out of 30 possible of the data source table. But I don't understand how to answer your question

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: How to get field value from form through X++

    You're focusing oin the single field and you're ignoring a much more important question: which record in the table are you editing when you're chaging the field?

    Don't waste time with thinking about the lookup, because it's irrelevant to you problem.

  • Julius Ellis Profile Picture
    5 on at
    RE: How to get field value from form through X++

    Hi Martin,

    I'm sorry if it is a bit confusing.

    I will try to enlighten my business requirement:

    We have a form with many fields. One of the fields is called "Person Name". Here, users can click the arrow button (drop down menu) and select one of the possible person names. From what I understood, this uses a lookup() method to open that mini menu. The manu displays two fields "Person" and "Description". The users then select one of the person and then save the form.

    Now, in an external class which has no connection to that form whatsoever, I want to pass the PersonName as a variable, in order to insert it in other code logic. So, for example, my requirement is to have string personName = "selected person on the form field". I'm having difficulties understanding how to achieve this. I found the table that contains the records (i.e., multiple names and multiple descriptions), but I want to select the one that is choosen on the other form, which is why I thought I needed to act upon the form and not the database table itself.

    Is it clear? I'm sorry

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: How to get field value from form through X++

    I'm sorry, but I can't tell you what your table represents and which record is the "correct" one for your needs. You need to analyze the business requirement. We know nothing about it, so we can't do it for you.

  • Julius Ellis Profile Picture
    5 on at
    RE: How to get field value from form through X++

    Hi Martin, thank you for your response!

    I understand what you mean. I should be focusing on the table benhind the form field rather than the form field itself, right? I found out the associated table and found the multiple records that show up on the lookup menu (when the users choose the value on the form). One of them is, precisely, Julius Ellis. My doubt is how to retrieve the "correct" value. Since there are multiple records, how do I know which one is the choosen one for that given time (on the form)?

  • Martin Dráb Profile Picture
    235,966 Most Valuable Professional on at
    RE: How to get field value from form through X++

    If the class is called from the form, you can pass a value from the form to the class.

    If it's not called from the form, it has no access to the form. Maybe the form isn't opened at all, or it's opened by a hundred users at the same time, but the class knows nothing about it. But that's not a problem when you start focusing on the right thing. A form is just a way how to allow users to manipulate with data. And you need the data, not the user interface, in your class. Let users set choose the value in a form and save it to database. Your class will read data from database, regardless of whether the value was set by users in a form, imported through data management, written by X++ code or by any other mean.

  • Julius Ellis Profile Picture
    5 on at
    RE: How to get field value from form through X++

    Hi André, thank you for your response.

    Is there some documentation regarding your suggestion? I understood the construct method but I'm not sure how to apply the modified() method of the control.

    The requirement is to get the value present on field X in form Y in a class which has nothing to do with the form (not extended or CoC). The idea would be each time we run the class, the code checks the form, checks the field and gets the value present. If the field is altered, then the next time we run the code the variable will have the newly altered field (which makes me wonder if I need the modified() part or if I just need a read field solution). Sorry if it's a bit confusing :/

  • Suggested answer
    André Arnaud de Calavon Profile Picture
    297,611 Super User 2025 Season 2 on at
    RE: How to get field value from form through X++

    Hi Julius,

    You can create a class with a construct method and one or more parm methods. The parm methods can be used to set or get variables.

    On initialization of the form, you can construct the class.

    With the modified() method of the control, you can call the parm method on the class to pass the value.

    Do you also have a requirement to pass the value when the user will select another record on the form?

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Sohaib Cheema Profile Picture

Sohaib Cheema 823 User Group Leader

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 491 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans