Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

javascript call action through web api

Posted on by 2,397

Hi, I am trying to call an action through web api, but it keeps giving me this error "Resource not found for the segment 'invoice'". It is an action associated with invoice entity, here is the javascript, did I miss anything?

function executeCompleteInvoice(){
  debugger;
  var organizationUrl = Xrm.Page.context.getClientUrl();
  var id = Xrm.Page.data.entity.getId().replace('{', '').replace('}', '');
  var query = "invoice("+id+")/Microsoft.Dynamics.CRM.actiontestinvoice123";
  var req = new XMLHttpRequest(); 
  req.open("POST", organizationUrl + "/api/data/v8.0/" + 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) { 
          req.onreadystatechange = null; 
          if (this.status == 200) { 
              alert("Action called successfully");

          } else { 
              var error = JSON.parse(this.response).error; 
              alert(error.message); 
          } 
      } 
  };
  req.send();
}	


*This post is locked for comments

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: javascript call action through web api

    That means that you're doing something wrong. Please provide your full code and screenshot of action.

  • sdnd2000 Profile Picture
    sdnd2000 2,397 on at
    RE: javascript call action through web api

    Thanks Andrew, but I still got error "request message has unresolved parameter", and I didn't send parameter

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: javascript call action through web api

    Have you tried to use invoices instead of invoice?

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