web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Add field to response in event

(2) ShareShare
ReportReport
Posted on by 99
Hello Dynamics 365 Community,
I need to extend an OData response, when we read an entity. I resently learned about extensions and tried to do it with them. I was also happy that I could hook on the postLoaded event to search for the needed data using select statements.
I have my information now but no clue how to add them to the response. I saw suggestions to add custom fields in extensions, but that is not working for me since I am extending a tableStr. (See my simplified code example below).
For a deeper understanding: I want to extend the Status of an ECO Header to the Response.
 
[ExtensionOf(tableStr(EngChgEngineeringChangeOrderHeaderEntity))]
final class EngChgEngineeringChangeOrderHeaderEntity_Extension
{

    [DataEventHandler(tableStr(EngChgEngineeringChangeOrderHeaderEntity), DataEventType::PostedLoad)]
    public static void EngChgEngineeringChangeOrderHeaderEntity_onPostedLoad(Common _sender, DataEventArgs _eventArgs)
    {
        // Get event data as entity
        EngChgEngineeringChangeOrderHeaderEntity ecoHeaderEntity = _sender as EngChgEngineeringChangeOrderHeaderEntity;
        
        // Perform actions in correct company
        changecompany(ecoHeaderEntity.DataAreaId)
        {
            // Read data from EngChgEcmHeader table (to also read Status)
            EngChgEcmHeader engChgEcmHeader;
            select RecId, Status from engChgEcmHeader
                where engChgEcmHeader.RecId == _sender.RecId;
           
            if (engChgEcmHeader)
            {
                print(engChgEcmHeader.Status);
            }
            
        }
    }

}
 
I am reaching out to you since I have the feeling I am doing something completly wrong. How do you solve something like that? 
 
Categories:
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,022 Most Valuable Professional on at
    Moved from Integration, Dataverse, and general topics forum.
     
    The correct solution is easier and better than your current approach. EngChgEcmHeader is already a data source of the entity (e.g. the OrderNumber field is bound to it), therefore you don't any additional select statement and a virtual field. Simply create a data entity extension (of EngChgEngineeringChangeOrderHeaderEntity) and add a new field bound to EngChgEcmHeader.Status). Because the entity supports data management, create also an extension of EngChgEngineeringChangeOrderHeaderStaging table and add a field of the same name (and EDT) there. And that's it; you don't need any code at all.
  • CH-11120820-0 Profile Picture
    99 on at
    Thank you for the quick answer. Maybe I am doing something wrong here. 
    When I am trying to add the field to the data source extension and the staging, my OData fetch request is not working anymore. This is my stacktrace:
     
    at Microsoft.Dynamics.Ax.MSIL.Interop.throwException(Int32 ExceptionValue, interpret* ip)\r\n   
    at Microsoft.Dynamics.Ax.MSIL.cqlCursorIL.NextRec(IntPtr table)\r\n   
    at Microsoft.Dynamics.Ax.Xpp.Common.NextRec() in D:\\dbs\\sh\\l23t\\0520_210300\\cmd\\b\\Source\\Kernel\\xppil\\XppSupport\\Common.cs:line 1038\r\n   
    at Microsoft.Dynamics.AX.Framework.Linq.Data.Msil.AxRecord.MoveNext()\r\n   
    at Microsoft.Dynamics.AX.Framework.Linq.Data.AxProjectionReader`1.Enumerator.MoveNext() in D:\\dbs\\sh\\l23t\\0520_210300\\cmd\\b\\Source\\Frameworks\\LinqToManagedInteropLayer\\Microsoft.Dynamics.Ax.Linq.Data\\AxProjectionReader.cs:line 280\r\n   
    at Microsoft.Dynamics.Platform.Integration.Services.OData.Query.QueryEvaluator.Evaluate(IQueryable query, IServicesRequestSessionProvider servicesRequestSessionProvider, IODataSecurityRights securityRights)\r\n   
    at Microsoft.Dynamics.Platform.Integration.Services.OData.Query.QueryEvaluator.Single(IQueryable query, IServicesRequestSessionProvider servicesRequestSessionProvider, IODataSecurityRights securityRights)\r\n   
    at Microsoft.Dynamics.Platform.Integration.Services.OData.AxODataController.Get()\r\n   
    at lambda_method(Closure , Object , Object[] )\r\n   
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   
    at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<CallOnActionExecutedAsync>d__5.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Filters.ActionFilterAttribute.<ExecuteActionFilterAsyncCore>d__0.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Tracing.Tracers.HttpControllerTracer.<ExecuteAsyncCore>d__5.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Tracing.ITraceWriterExtensions.<TraceBeginEndAsyncCore>d__18`1.MoveNext()\r\n
    --- End of stack trace from previous location where exception was thrown ---\r\n   
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   
    at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()
     
    Maybe I am not adding the fields correctly. Is there any documentation/video on how to add these fields? 
  • Verified answer
    Waed Ayyad Profile Picture
    9,089 Super User 2026 Season 1 on at
    Hi,
     
    Did you do full build and Sync database after you added the new field? Also did you refresh entity list?
     
    Check the following link about adding new field to data entity using extension: d365ffo-ax-add-new-field-to-a-data-entity
     
    Also check the following link about refresh entity list: d365-finance-missing-data-entities-refresh-entity-list
     

    Thanks,

    Waed Ayyad

    If this helped, please mark it as "Verified" for others facing the same issue

  • Waed Ayyad Profile Picture
    9,089 Super User 2026 Season 1 on at

    Hi, 

    Is your issue resolved? If yes, mark the answers that helped you as verified. 

    Thanks,

    Waed Ayyad

  • CH-11120820-0 Profile Picture
    99 on at
    Thank you!
  • Waed Ayyad Profile Picture
    9,089 Super User 2026 Season 1 on at
     
    Can you verify the answer that helped you.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 617

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 461 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 298 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans