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, ...
Answered

Set a line field to a header field when I "Add line".

(0) ShareShare
ReportReport
Posted on by 26

Hello.

Im new to Dynamics and this is probably really simple but I cant get it to work.

When I Add a new line Id like some of the fields to be automatically filled in. For example I want to copy a value from the header into a field on the new line. 

I tried to simply do tableA_field = tableB.field; in the Control for AddLine under clicked(); However the fields in the new line is still empty. 

What is the correct way of setting line fields to something upon adding them? 

I have the same question (0)
  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi Dushatar,

    You can make use of Datasource level initvalue method or table level initvalue method to default initial values to the form upon adding new line.

    In your case you need to default header values to line, So write the code in line datasource initvalue method.

    Thanks,

    Girish S.

  • Dushatar Profile Picture
    26 on at

    I think I got it to work.

    I added it under the create method in the table which also calls initValue().

    Does that seem reasonable? It seem to do what I wanted it to (values are now set when I create new lines).

    Thank you =)

  • GirishS Profile Picture
    27,827 Moderator on at

    Yeah you can make use of create method also.

    Difference is when using init value method the new values are not automatically saved to the database when you leave the form.

    To specify values that you want to save when you leave the form, Create method will be used.

    Thanks,

    Girish S

  • Dushatar Profile Picture
    26 on at

    So if I understand you correct.

    If I use initValue method it will only be saved to db when I press "save"?

    If I use create method it will be saved to db as soon as the line is created?

  • Verified answer
    GirishS Profile Picture
    27,827 Moderator on at

    For example if your table has mandatory fields - Now you use create method to initialize value other than mandatory fields. So now you leave the form without giving value for mandatory fields, A new record will be created in the table without mandatory fields - This will create a orphan records in the table which should be avoided.

    So my suggestion will be using the initvalue method to initialize the values instead of create method.

    Thanks,

    Girish S.

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