Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Error while Invoking Action from JavaScript "Resource not found for the segment"

Posted on by 802

Hi, I am trying to Invoke an Action from JavaScript. But getting the following error message:

Resource not found for the segment Microsoft.Dynamics.CRM.abc_CreateRecurringPaymentRequests

Code is as Below:

function handleRecurringPaymentRequest() {
    var functionName = "abc_CreateRecurringPaymentRequests";
    var quoteId = Xrm.Page.data.entity.getId();
    quoteId = quoteId.replace(/[{}]/g, "");
    var result;

    try {
        var query = "quotes(" + quoteId + ")/Microsoft.Dynamics.CRM." + functionName;
        var clientUrl = Xrm.Page.context.getClientUrl();
        var req = new XMLHttpRequest();
        req.open("POST", clientUrl + "/api/data/v9.1/" + query, true);
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");

        req.onreadystatechange = function () {

            if (this.readyState == 4 /* complete */) {
                req.onreadystatechange = null;

                if (this.status == 200) {
                    //success callback
                    result = JSON.parse(this.response);
                } else {
                    //error callback
                    var error = JSON.parse(this.response).error;
                    alert(error.message);
                }
        }
};
req.send();

} catch (e) {
    alert(e.message);
}

alert(result.newRprUrl);
}

I have checked using the link below and Action is available in metadata:

https://myorgname.crm4.dynamics.com/api/data/v9.1/$metadata

*This post is locked for comments

  • Suggested answer
    Hayer Profile Picture
    Hayer 802 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Thanks for your responses. As per Ravi's suggestion, I tried CRM REST builder and custom action was there in the list. Then I generated the query using REST builder and everything started working. Looks like something was wrong with my query. Thanks

  • Kalpavruksh D365 CoE Profile Picture
    Kalpavruksh D365 CoE 2,545 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Hi,

    Please check your action abc_CreateRecurringPaymentRequests. This might be deactivated for some reason. Kindly activate your custom action.
  • Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Please check if your action is in ACTIVATED or Draft state under Setting -> Processes. 

    Refer to following blogs for other verification to check for such error.

    https://vjcity.blogspot.com/2019/07/resource-not-found-for-segment-error.html

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Hi P.S. Hayer,

    Please try with api version 8.2 with synchronous service.

    req.open("POST", clientUrl + "/api/data/v8.2/" + query, false);

    also make sure that action is activated 

  • RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    What I noticed when I had the same issue, was that if I created a new action, it worked fine and the action was "found" when calling it from javascript.

    I got to use the initial action, only after a server restart. I assume that with CRM Online it would eventually stop throwing the error and find the action after some time, when that specific cache is cleared.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Hi,

    Based on the error message, it looks like that CRM is unable to find the action with that name. I would suggest to try it in CM Rest Builder and see if you get your action their. If you do see it there, refer the code to get the name. There are some known caching issue when you delete/ reactivate the custom action. So if nothing works, try creating a custom action again with some different/ new name.

    Hope this helps.

  • Hayer Profile Picture
    Hayer 802 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    Hi Florian, Thanks for your suggestions. I have tried it but no luck.

  • Suggested answer
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    I remember having a similar issue on a CRM onpremise org and it was caused by some cache. It worked after rebooting the server (but I didn't try anything else either). Re-publishing all, didn't actually help to invalidate the cache.

    As this is CRM Online, maybe try using a different browser or remove everything from the browser's cache.

  • Hayer Profile Picture
    Hayer 802 on at
    RE: Error while Invoking Action from JavaScript "Resource not found for the segment"

    I have also tried to access it from browser by using the Url below:  

    myorgname.crm4.dynamics.com/.../Microsoft.Dynamics.CRM.abc_CreateRecurringPaymentRequests

    But it returns the following error:

    {"error":{"code":"0x0","message":"Resource not found for the segment 'Microsoft.Dynamics.CRM.abc_CreateRecurringPaymentRequests'","innererror":{"message":"Resource not found for the segment 'Microsoft.Dynamics.CRM.abc_CreateRecurringPaymentRequests'","type":"Microsoft.Crm.CrmHttpException","stacktrace":"   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRoutingConvention.ThrowUnresolvedSegmentException(ODataPath odataPath)\r\n   at Microsoft.Crm.Extensibility.ODataV4.Routing.CrmODataRoutingConvention.SelectActionImplementation(ODataPath odataPath, HttpControllerContext controllerContext, ILookup`2 actionMap)\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 System.Web.OData.Routing.ODataActionSelector.SelectAction(HttpControllerContext controllerContext)\r\n   at System.Web.Http.ApiController.ExecuteAsync(HttpControllerContext controllerContext, CancellationToken cancellationToken)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}}}

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