Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested answer

How to populate missing fields after free text invoice imported using Customer free text invoice entity

(0) ShareShare
ReportReport
Posted on by

Hi I am using Customer free text invoice data entity to import free text invoice.  The entity has Customer invoice table and Customer invoice line as the data source.  I would like to populate missing fields on Customer invoice line using event, which event I should be using?  And should I use event on the data entity or table?  When writing event handler, how to get Customer invoice line data source when Customer invoice table is the top level data source?

Thanks!

  • Sangram Shinde Profile Picture
    2,094 on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    Did you find any error details in event viewer?

    Regards,

    Sangram

  • Suggested answer
    Khushhal Garg Profile Picture
    1,514 on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    can you try restarting iisexpress.exe. which IIS version are you running? Switch iisexpress to w3wp process. It should resolve debugging issue.

  • Community Member Profile Picture
    on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    I built the model and synchronized database.  I put breakpoint and attach the debugger to iisexpress.exe but it didn't stop there.  I seem always not be able to debug any event handler for entity, it never stops there.

  • Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    put breakpoint in mappedEntityTOdatasource and see  when you are getting the error. Did you build your model where you implemented this event ?

  • Community Member Profile Picture
    on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    Hi Sukrut,

    Thanks so much for your help.  I added the following code and do the data import, but the data import failed with no specific error.  The import would succeed if there is no event handling.  The event handling is trying to populate the billing code rate and ledger dimension because the out of box entity doesn't do that.  I tried to set break point in event handling method but it doesn't stop there when I attached the debugger to iisexpress.exe.  Any suggestion on what I did wrong?

    class FreeTextInvoiceEntityEventHandler

    {

       /// <summary>

       ///

       /// </summary>

       /// <param name="_sender"></param>

       /// <param name="_eventArgs"></param>

       [DataEventHandler(tableStr(FreeTextInvoiceEntity), DataEventType::MappedEntityToDataSource)]

       public static void FreeTextInvoiceEntity_onMappedEntityToDataSource(Common _sender, DataEventArgs _eventArgs)

       {

           DataEntityContextEventArgs          entityContextEventArgs = _eventArgs as DataEntityContextEventArgs;

           DataEntityRuntimeContext            entityCtx = entityContextEventArgs.parmEntityContext();

           DataEntityDataSourceRuntimeContext  dataSourceCtx = entityContextEventArgs.parmEntityDataSourceContext();

           CustBillingCode                 custBillingCode;

           CustBillingCodeVersion          custBillingCodeVersion;

           CustBillingCodeRate             custBillingCodeRate;

           CustBillingCodeLedgerAccount    custBillingCodeLedgerAccount;

           if (dataSourceCtx.name() == dataEntityDataSourceStr(FreeTextInvoiceEntity, CustInvoiceLine ))

           {

               CustInvoiceLine custInvoiceLine = dataSourceCtx.getBuffer();

               if (custInvoiceLine.AmountCur == 0)

               {

                   select RecId from custBillingCode

                       where custBillingCode.BillingCode == custInvoiceLine.BillingCode;

                   if (custBillingCode.RecId != 0)

                   {

                       select RecId, RateFieldSelector from custBillingCodeVersion

                               where custBillingCodeVersion.CustBillingCode == custBillingCode.RecId;

                   }

                   if (custBillingCodeVersion.RecId != 0)

                   {

                       select Amount from custBillingCodeRate

                           where custBillingCodeRate.CustBillingCodeVersion == custBillingCodeVersion.RecId;

                       select LedgerDimension from custBillingCodeLedgerAccount

                               where custBillingCodeLedgerAccount.CustBillingCodeVersion == CustBillingCodeVersion.RecId;

                       if (custBillingCodeRate.Amount != 0)

                       {

                           if (custBillingCodeVersion.RateFieldSelector == RateField::LineAmount)

                           {

                               custInvoiceLine.AmountCur = custBillingCodeRate.Amount;

                               custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;

                           }

                           else

                           {

                               custInvoiceLine.UnitPrice = custBillingCodeRate.Amount;

                               custInvoiceLine.AmountCur = custInvoiceLine.UnitPrice * custInvoiceLine.Quantity;

                           }

                       }

                       if (custBillingCodeLedgerAccount.LedgerDimension != 0)

                       {

                           custInvoiceLine.LedgerDimension = custBillingCodeLedgerAccount.LedgerDimension;

                       }

                   }

               }

           }

       }

    }  

  • Suggested answer
    Sukrut Parab Profile Picture
    71,682 Moderator on at
    RE: How to populate missing fields after free text invoice imported using Customer free text invoice entity

    I replied on your another thread . You are using a correct event  onMappedEntityToDataSource . You have to just assign values   to your field in this method and rest of the things are taken care.

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,118 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans