Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Error Custom Javascript after update from CRM Online 8.2 to 9.0

Posted on by 60

Hello Everyone,

I have a custom code to close an incedent. that is running, when we press one custom botton in the form Case...

with the version V8.2 works properly but with the V9.0 I have the below error. I am ussing the Api to do that. and of course I updated the API number version.

and when I run the botton the below error appeared.

Anyone have any suggestion

 

at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)

↵ at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request, ExecutionContext executionContext)

↵ at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)

↵ at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)

↵ at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass9_0.<PostUnboundAction>b__0()

↵ at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)

↵ at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)

↵ at lambda_method(Closure , Object , Object[] )

↵ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)

↵ at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

↵--- End of stack trace from previous location where exception was thrown ---

↵ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

↵ at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()

↵--- End of stack trace from previous location where exception was thrown ---

↵ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

↵ at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()

↵--- End of stack trace from previous location where exception was thrown ---

↵ at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()

↵ at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)

↵ at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()

---------------------------------------------------------------------------------------------------------------------------------

This is a copy of the javascripto code. 

java.png

*This post is locked for comments

  • jdalske Profile Picture
    jdalske 536 on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    I found this and it was super helpful.  Cleared almost all my errors identified by the Dynamics JavaScript Validator.

    https://www.crmug.com/communities/community-home/digestviewer/viewthread?MessageKey=0ce77e0d-60e2-4d6a-a808-6c78f09e4edb&CommunityKey=dc83c23b-ede0-4070-ae7a-dd90859148a6&tab=digestviewer

    I just have a few errors left.

    Method openEntityForm must be replace with Xrm.Navigation.openForm

    And it looks like this might be useful

    https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/Xrm-Navigation/openForm

  • Suggested answer
    Jim Daly Profile Picture
    Jim Daly on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    I found the error in my code.

    I used this:

    "incidentid@odata.bind": "/incidents/(" + incidentid + ")",

    I should have used this:

    "incidentid@odata.bind": "/incidents(" + incidentid + ")",

    I tested the following function in both v8.2 and v9.0. It worked for both

    var ns = {
    
        resolveIncident: function (subject, incidentid, timespent, description) {
            var incidentResolution = {
                "subject": subject,
                "incidentid@odata.bind": "/incidents(" + incidentid + ")",
                "timespent": timespent,
                "description": description
            };
    
            var parameters = {
                "IncidentResolution": incidentResolution,
                "Status": 5
            };
    
            var req = new XMLHttpRequest();
            req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/CloseIncident", 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.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 204) {
                        console.log("Successfully resolved incident")
                    } else {
                       console.log(JSON.parse(this.response).error.message)
                       
                    }
                }
            };
            req.send(JSON.stringify(parameters));
        }
    };
    
    ns.resolveIncident("Close Case", "A44ECC5C-8BAB-E611-80F5-3863BB2E03E0", 60, "Additional Description here");


  • Miguel laines Profile Picture
    Miguel laines 60 on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    Hello Jim

    yes, I added code to see the error, but the error  messages it is not suitable to resolve something..

    I dont really know what could be the issue, I opened a tickect to Microsoft to follow up, once I have something I will put it here in the post.  

    {"error":{"code":"0x80040265","message":"OrganizationServiceFault","innererror":{"message":"OrganizationServiceFault","type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":"   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request, ExecutionContext executionContext)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteOperation(CrmODataExecutionContext context, EdmOperation edmOperation, Dictionary`2 parameters, Dictionary`2 boundParameters)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.ProcessOperationRequest(String operationName, Dictionary`2 operationParameters, EntityReference entityReference, String boundEntityName, String boundEntityType)\r\n   at Microsoft.Crm.Extensibility.OData.ActionController.<>c__DisplayClass9_0.<PostUnboundAction>b__0()\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()"}}}

  • Jim Daly Profile Picture
    Jim Daly on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    You have provided the stack trace, but I don't see the simple error I expect.

    If you replace:

    var errorText = this.responseText

    with this:

    var errorText =JSON.parse(this.response).error.message

    I think you will get something more meaningful than the stacktrace you are seeing.

    If you get 'Empty segment encountered in request URL. Please make sure that a valid request URL is specified.' - then you are getting the same thing I'm getting and it might be a bug.

    This is a function I wrote to test this:

    var ns = {
    
        resolveIncident: function (subject, incidentid, timespent, description) {
            var incidentResolution = {
                "subject": subject,
                "incidentid@odata.bind": "/incidents/(" + incidentid + ")",
                "timespent": timespent,
                "description": description
            };
    
            var parameters = {
                "IncidentResolution": incidentResolution,
                "Status": 5 //Problem solved
            };
    
            var req = new XMLHttpRequest();
            req.open("POST", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/CloseIncident", 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.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 204) {
                        console.log("Successfully resolved incident")
                    } else {
                       console.log(JSON.parse(this.response).error.message)
                       
                    }
                }
            };
            req.send(JSON.stringify(parameters));
        }
    };


    This is how you call it:

    ns.resolveIncident("Close Case", "a44ecc5c-8bab-e611-80f5-3863bb2e03e0", 60, "Additional Description here");


    It is late and I am tired, so I might have made some error.

  • Miguel laines Profile Picture
    Miguel laines 60 on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    .

  • Miguel laines Profile Picture
    Miguel laines 60 on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    Hello Adrian  

    Thank you so much for your help, but the issue is not releated with the deprecated things in Vs9.0 as  Microsoft mentioned,  “Deprecated” means we intend to remove the feature or capability from a future major release of Dynamics 365.  so the XRM.Page should be work in this version... and yes,  the tool just mention

    ----Line number 22: Method Xrm.Page must be replace with ExecutionContext.getFormContext

    ----Line number 22: Method Xrm.Page.context must be replace with Xrm.Utility.getGlobalContext

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    Hi Miguel,

    The problem is posible in the use Xrm.Page.Context, in the new version is used Xrm.Utility.getGlobalContext, in the new version is present changes in the actions from javascript, in the link describe the deprecated client API in javascript and the replace code.

    docs.microsoft.com/.../important-changes-coming

    Regards...

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Error Custom Javascript after update from CRM Online 8.2 to 9.0

    Hi Miguel Laines,

    Run your JavaScript code through the Dynamics 365 V9 Javascript Validator in the XrmToolBox.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans