Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Updating form text fields programmatically

(0) ShareShare
ReportReport
Posted on by

I need to add some custom validation to some existing AX forms based on some business rules.  If the data on the field meets a certain criteria, I need to update the value of the text field programmatically.  Since this customization will be applied across many forms, i've created a class which implements the logic and have added a menu button to the forms that invokes the method in my class.  The class uses the FormRun.form().design() method to recursively discover all the FormStringControl objects on the form and calls its text() object to retrieve the current value of the control.  The issue is that calling the myFormStringControlObject.text([str]) and providing a new value does not change the value of the field.  I don't want to update the database directly because I want the user to cancel out without saving. My question is, how do i go about updating a field on a form dynamically without committing it to database first?  is there any other method to call after calling the text([str]) method in order for the change to take effect?

Thanks

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Updating form text fields programmatically

    As I can understand your requirement

    you are basically need where you have controls on the form

    you enter or populate date in it but it should not update the table automatically

    For this purpose controls (Text box) on the form should not be database bound

    To have this you should not assign datasource and data field property for the control

    now if you use myFormStringControlObject.text([str]) method it will work as per you requirement and will not update the database automatically

    now if you implement such kind of feature then you need to have a save button on the form which will basically update the database when it is clicked.

    Please verify and update us if this helps you

  • Mohammad Raziq Ali Profile Picture
    2,472 on at
    RE: Updating form text fields programmatically

    yes, you can update the control if it is bounded field and use Ds.refresh method in your code.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Updating form text fields programmatically

    Instead of playing on forms control, I would suggest you to create temporary table containing all your fields required on form and apply the logic on temporary table. This will surely reduce your effort.

    Hope this helps you

  • KyleLeBarre Profile Picture
    745 on at
    RE: Updating form text fields programmatically

    Yup...I don't think you can change the text on a string control if its bound to a datasource field. Going this route would probably be the best. After setting the value, you'd need to refresh the DS.

    You'd probably also want to comment out the super() in the datasource's write() method and then take care of committing to the DB when you close the form(or whatever event should trigger the commit)

  • Verified answer
    Bilal Issa Profile Picture
    4,370 on at
    RE: Updating form text fields programmatically

    Hi,

    I suggest you use dataSource, dataField properties on string control , and then update the field not the control, example

    formDataSource = myFormStringControlObject.DataSource();

    formDataSource.object(fieldId).setValue('Value');

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... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,002 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans