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:
*This post is locked for comments
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
Hi,
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
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
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.
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.
Hi Florian, Thanks for your suggestions. I have tried it but no luck.
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.
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()"}}}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156