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? 

  • Verified answer
    GirishS Profile Picture
    27,823 Moderator on at
    RE: Set a line field to a header field when I "Add line".

    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.

  • Dushatar Profile Picture
    26 on at
    RE: Set a line field to a header field when I "Add line".

    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?

  • GirishS Profile Picture
    27,823 Moderator on at
    RE: Set a line field to a header field when I "Add line".

    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
    RE: Set a line field to a header field when I "Add line".

    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 =)

  • Verified answer
    GirishS Profile Picture
    27,823 Moderator on at
    RE: Set a line field to a header field when I "Add line".

    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.

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,276 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,975 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans