Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / How to assign value to...
Finance forum
Answered

How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

Posted on by 932

Hi all,

I hav a Form name MyForm with Datasources DSA, DSB. i will type a value in DSA-field1. now i need to assign this value in DSB- field2. i am trying in FormDataFieldEventhandler.

how to fetch other datasource record (DSB) here while modifying DSA-fieldlevel.

Any suggestions plss.

Thanks in advance,

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Sergio,

    i will try your suggestion as well. thanks for the quick reply.

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Mattguo,

    Thanks . it worked.

  • Verified answer
    MATTGUO Profile Picture
    MATTGUO 22,296 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Test Bot,

    You could use the below code, SalesTable>DSA ,SalesLine>DSB:  

    [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesTable, AccountingDistributionTemplate), FormDataFieldEventType::Modified)]

       public static void AccountingDistributionTemplate_OnModified(FormDataObject sender, FormDataFieldEventArgs e)

       {

           FormRun formRun = sender.datasource().formRun();

           FormDataSource salesline_ds = formRun.dataSource("SalesLine");

           salesline_ds.yourfield=......

       }

  • Suggested answer
    Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,083 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Test Bot,

    In this case, I still suggest using "OnWritten' event and update_recordset with DSB data source refresh option. In this case, if user will change values several times, you don't need to do unecesary updates to DSB before user decide to fix changes.

  • Shaik146 Profile Picture
    Shaik146 932 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Nikolaos and Sergei,

    thanks for your suggestions .

    Its a standard form. i need at form level modifying the data.

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,148 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Why do you want to duplicate this value in the other table / data source? Normally you should try to avoid that, instead store the data in one place and access it via table relations from other places.

    Anyway, if you do, and if it's your own form, you don't need to use event handlers (as Sergey mentioned).

    And you could also consider putting the code in insert and update (and delete?) methods of the table, instead of the form. This way the logic would work from any process that writes into that table.

  • Suggested answer
    Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,083 on at
    RE: How to assign value to formdatasource field when modifying other formdatasource field in d365 using eventhandler

    Hi Test Bot,

    If MyForm is your own form, you don't need to use event handlers. Use methods on form instead.

    I would recommend using 'write' method on DSA data source and after 'super' statement update value in DSB table with update_recordset statement and refreshing DSB data source.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans