Skip to main content

Notifications

Dynamics 365 general forum

Execute custom action using web api issue

Posted on by 680

Hi,

We have created custom action and we are executing it using the web api (using script). When we added two output parameters in custom action then it throws following error.

Resource not found for the segment.

When we remove second output parameter then it execute without error. 

Is anyone face same kind of issue and solution for it.

Thanks!

Balasaheb   

  • Balasaheb Profile Picture
    Balasaheb 680 on at
    RE: Execute custom action using web api issue

    Hi Goutam,

    Here is the screenshot of our custom action.

    3515.Untitled.png

    Here is the web api code that we used to execute this action. When we remove string output parameter then it execute successfully when we add string output parameter then it throw error.

    function executeCustomAction() {

       try {

           var actionObj = {

               A1: "test1",

               A2: "test2"

           }

           // call this function to execute the action

           execute(actionObj, "ikl_TEST_CA()", function (data) {

               alert("Success: " + data);

           }, function (error) {

               debugger;

               alert("Error: " + error.message);

           });

       } catch (e) {

           alert(e.message);

       }

    }

    function execute(req, reqName, successCallback, errorCallback) {

       //create AJAX request

       $.ajax({

           type: "POST",

           contentType: "application/json; charset=utf-8",

           datatype: "json",

           url: encodeURI(getWebAPIPath() + reqName),

           data: window.JSON.stringify(req),

           beforeSend: function (xhr) {

               //Specifying this header ensures that the results will be returned as JSON.            

               xhr.setRequestHeader("Accept", "application/json");

               //xhr.setRequestHeader("Content-Type", "application/json; charset=utf-8");

               xhr.setRequestHeader("OData-MaxVersion", "4.0");

               xhr.setRequestHeader("OData-Version", "4.0");

           },

           success: function (data, textStatus, xhr) {

               //successCallback function

               if (data != null && data.value != undefined) {

                   successCallback(data.value);

               } else {

                   successCallback(data);

               }

           },

           error: function (xhr, textStatus, errorThrown) {

               errorCallback(Inogic.Maplytics.ApiLib.errorHandler(xhr));

           }

       });

    }

    function getWebAPIPath() {

       return Xrm.Page.context.getClientUrl() + "/api/data/v8.0/";

    }

  • Balasaheb Profile Picture
    Balasaheb 680 on at
    RE: Execute custom action using web api issue

    Hi Gaurav,

    Thanks for your reply.

    I am passing same type of entity. When we pass only Entitycollection parameter then it work. But when we pass Another output parameter along with Entitycollection parameter.

    Thanks

  • talk2.gauravb Profile Picture
    talk2.gauravb 120 on at
    RE: Execute custom action using web api issue

    Are you passing different types of entity in collection or of one same type. I have used EntityCollection as output parameter and it works fine for me.

    If you can share code maybe i can help you out

  • Balasaheb Profile Picture
    Balasaheb 680 on at
    RE: Execute custom action using web api issue

    Hi,

    We have troubleshoot this issue and found that when we define two output parameter out of which one is EntityCollection type and other is string then above error throws. When we define both parameter as string type then it works properly.  

    Is anyone face same kind of issue and have solution for it.

    Thanks!

    Balasaheb

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Execute custom action using web api issue

    This error happen when you are provide wrong parameter name ,check your parameter name , use schema name if its fields.

    Also please share your code for more understanding your code if you can,

  • T.I.A Profile Picture
    T.I.A 1,760 on at
    RE: Execute custom action using web api issue

    Could you provide some code for context?

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,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