Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

How to retrieve linked entity field value in javascript

Posted on by 475

Hello,

I want to get fields values of fcpm_technologyname, fcpm_resourcename from the linked entity query pls suggest how to assign values of those field to variable ?

var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/fcpm_fieldtaskactivities?$select=_fcpm_activity_value&$expand=fcpm_Activity($select=fcpm_technologyname,fcpm_resourcename)", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.response);
for (var i = 0; i < results.value.length; i++) {
var _fcpm_activity_value = results.value[i]["_fcpm_activity_value"];
var _fcpm_activity_value_formatted = results.value[i]["_fcpm_activity_value@OData.Community.Display.V1.FormattedValue"];
var _fcpm_activity_value_lookuplogicalname = results.value[i]["_fcpm_activity_value@Microsoft.Dynamics.CRM.lookuplogicalname"];
//Use @odata.nextLink to query resulting related records
var fcpm_Activity_NextLink = results.value[i]["fcpm_Activity@odata.nextLink"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();

Thanks,

Krishna Prasad.

  • Joana Pinto Profile Picture
    Joana Pinto 740 on at
    RE: How to retrieve linked entity field value in javascript

    Hi,

    On the expand property:

    $expand=fcpm_Activity($select=fcpm_technologyname,fcpm_resourcename)

    You must put on select that field you want to bring on your result.

    $expand=fcpm_Activity($select=fcpm_technologyname,fcpm_resourcename,fcpm_actionname)

  • dkrishna Profile Picture
    dkrishna 475 on at
    RE: How to retrieve linked entity field value in javascript

    iam getting below error when i run it but query is build is built from crmrestbuilder even iam same error when i run from restbuilder . please suggest.

    "{"error":{"code":"0x0","message":"Could not find a property named 'fcpm_actionname' on type 'Microsoft.Dynamics.CRM.fcpm_activity'.","innererror":{"message":"Could not find a property named 'fcpm_actionname' on type 'Microsoft.Dynamics.CRM.fcpm_activity'.","type":"Microsoft.OData.ODataException","stacktrace":"   at Microsoft.OData.UriParser.SelectPathSegmentTokenBinder.ConvertNonTypeTokenToSegment(PathSegmentToken tokenIn, IEdmModel model, IEdmStructuredType edmType, ODataUriResolver resolver, BindingState state)\r\n   at Microsoft.OData.UriParser.SelectPropertyVisitor.ProcessTokenAsPath(NonSystemToken tokenIn)\r\n   at Microsoft.OData.UriParser.SelectPropertyVisitor.Visit(NonSystemToken tokenIn)\r\n   at Microsoft.OData.UriParser.SelectBinder.Bind(SelectToken tokenIn)\r\n   at Microsoft.OData.UriParser.SelectExpandBinder.GenerateExpandItem(ExpandTermToken tokenIn)\r\n   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()\r\n   at System.Linq.Enumerable.WhereEnumerableIterator`1.MoveNext()\r\n   at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)\r\n   at Microsoft.OData.UriParser.SelectExpandBinder.Bind(ExpandToken tokenIn)\r\n   at Microsoft.OData.UriParser.SelectExpandSemanticBinder.Bind(ODataPathInfo odataPathInfo, ExpandToken expandToken, SelectToken selectToken, ODataUriParserConfiguration configuration, BindingState state)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpandImplementation(String select, String expand, ODataUriParserConfiguration configuration, ODataPathInfo odataPathInfo)\r\n   at Microsoft.OData.UriParser.ODataQueryOptionParser.ParseSelectAndExpand()\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ThrowIfExpandWithRefForNonLookupNavProp(ODataQueryOptions queryOptions, String edmEntityName)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.<>c__DisplayClass35_0.<GetEntitySetInternal>b__1()\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute(ILogger logger, EventId eventId, ActivityType activityType, Action action, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute(ILogger logger, XrmTelemetryActivityType activityType, Action action)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetInternal(String entitySetName, String castedEntityName, CrmODataExecutionContext context, CrmEdmEntityObjectCollection crmEdmEntityObjectCollection, ODataQueryOptions queryOptions)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySetImplementation(String entitySetName)\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\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.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.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.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}}}"

  • Suggested answer
    Naveen Ganeshe Profile Picture
    Naveen Ganeshe 3,393 User Group Leader on at
    RE: How to retrieve linked entity field value in javascript

    Hello Krishna,

    Please try below code snippet to get and assign the values from the linked entity

    for (var i= 0; i < result.fcpm_Activity.length; i++) {

                   var  fcpm_technologyname = result.fcpm_Activity[i]["fcpm_technologyname"];

                   var  fcpm_resourcename = result.fcpm_Activity[i]["fcpm_resourcename"];

               }

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans