Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Creating a form which will add records to two tables

Posted on by 280

Hi all

Running AX 2012 R3 CU9.

My situation is this:

I've created two simple tables for record-keeping purposes (Let's call them Table1 and Table2). They're linked logically, one-to-many by a primary key field. I would like to create a simple form that has text input:

FieldA

FieldB

FieldC

FieldD

I would then like to hit OK and have the form populate a record in [Table1.FieldA, Table1.FieldB, and Table1.FieldC], but populate a record in TableB, TableB.FieldD .

My question is, what is the easiest way to do this? Does the form need to have both tables as data sources? Does it need neither but just have x++ code writing insert() on the button?

Any help would be much appreciated. Thanks very much in advance

Luke

*This post is locked for comments

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Creating a form which will add records to two tables

    valueStr() will return the value in string, like the name of the function suggests.

    Use selection() method to get the selected enum value.

  • lukbel Profile Picture
    lukbel 280 on at
    RE: Creating a form which will add records to two tables

    Hi Prasad

    I have now set this up - all working now! :)

    Thanks so much for your help

  • Suggested answer
    Prasad.V Profile Picture
    Prasad.V 185 on at
    RE: Creating a form which will add records to two tables

    Like I said below you can make the AutoDeclaration property of the control to 'Yes' so that you can call it directly like newuser.valueStr()

  • Prasad.V Profile Picture
    Prasad.V 185 on at
    RE: Creating a form which will add records to two tables

    What do you mean by "lift the value"? for reading the value from ComboBox/ StringEdit you can use valueStr() or text() method on the control but make sure you set AutoDeclaration property of the control to 'Yes'.

  • lukbel Profile Picture
    lukbel 280 on at
    RE: Creating a form which will add records to two tables

    Worked out how to pull the value from the blank ComboBox!

    Leaving it here so no one else has to piece together multiple pieces of documentation haha

    You can get the value from any form control by saying:

    element.design().controlName("newUser").valueStr()

    This returns it in a string format, mine was a recId so I used:

    str2recId(element.design().controlName("newUser").valueStr());

    Thanks very much for all your help :)

  • lukbel Profile Picture
    lukbel 280 on at
    RE: Creating a form which will add records to two tables

    Ahh thank you so much for your advice, Prasad and Sukrut

    I have one follow-up question if that is ok.

    When using insert record method, how can I lift the value from a form object such as a ComboBox or a StringEdit?

    Apologies if this is basic, I've never had need to create input that couldn't be accomplished by instructing user to use "Ctrl+N" haha

  • Prasad.V Profile Picture
    Prasad.V 185 on at
    RE: Creating a form which will add records to two tables

    Luke,

    If you don't have to display all the previously inserted records then you don't need to have data sources and overriding button clicked method will help to insert the records.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans