CRM 2013: Calling actions from javascript

若如初见. 提交于 2019-12-06 06:15:29

Typo!

req.setRequestHeader("SOAPAction", 
"http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationServic/Execute");

"IOrganizationServic" needs an 'e' appended.

Are you using the SOAPLogger?

The function looks ok. I can’t see the actual call so ensure that all values are properly encoded before you send the request. MS uses the following sample to encode the values. Personally, I would replace the concatenation (string buffer) of the XmlEncode value with an array buffer to boost the performance.

function loadAction() {
    var reason = XmlEncode("custom string");
    var entityId = XmlEncode(Xrm.Page.data.entity.getId());
    var entityName = "serviceappointment";
    var requestName = "new_entityname";
    //call function with encoded values ...
    ExecuteActionCreateProject(reason, entityId, entityName, requestName);
}


XmlEncode = function (strInput) {
  var c, XmlEncode = '';

  if (strInput == null) { return null; }
  if (strInput == '') { return ''; }

  for (var cnt = 0; cnt < strInput.length; cnt++) {
   c = strInput.charCodeAt(cnt);

   if (((c > 96) && (c < 123))  ||  
        ((c > 64) && (c < 91))  ||
          (c == 32)             ||
     ((c > 47) && (c < 58))     ||
       (c == 46)        ||
       (c == 44)        ||
       (c == 45)        ||
       (c == 95)) {
      XmlEncode = XmlEncode + String.fromCharCode(c);
       }
       else {
       XmlEncode = XmlEncode + '&#' + c + ';';
     }
  }

     return XmlEncode;
  } 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!