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)

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

I have the same question (0)
  • Verified answer
    Bilal Issa Profile Picture
    4,370 on at

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

  • KyleLeBarre Profile Picture
    747 on at

    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
    Community Member Profile Picture
    on at

    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

  • Mohammad Raziq Ali Profile Picture
    2,486 on at

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

  • Suggested answer
    Community Member Profile Picture
    on at

    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

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