如何使用Web Api操作AddSolutionComponent使用javascript将实体添加

我想使用JavaScript将自定义实体添加到Dynamics CRM中的自定义解决方案中。我已经进行了一些研究,结果发现可以使用Actions来完成。 AddSolutionComponent应该可以完成这项工作,但由于出错了,我可能出了点问题400 Request message has unresolved parameters。


我要传递参数的实体和解决方案都使用javascript创建,并且可以在crm中找到它们。


function associateEntityToSolution(entityId, solutionUniqueName, newSolutionId){


  var param = { 

      'ComponentId': entityId , // newly created entity id 

      'ComponentType':1, // entity type

      'SolutionUniqueName':solutionUniqueName,  //newly created solution id

      'AddRequiredComponents':false,

      'IncludedComponentSettingsValues':null

  };


  var req = new XMLHttpRequest();

  req.open("POST", window.parent.opener.Xrm.Page.context.getClientUrl() + "/api/data/v8.2/solutions("+newSolutionId+")/Microsoft.Dynamics.CRM.AddSolutionComponent", true);

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

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

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

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

  req.onreadystatechange = function() {

      if (this.readyState === 4) {

          req.onreadystatechange = null;

          if (this.status === 204) {

              var uri = this.getResponseHeader("OData-EntityId");

              var regExp = /\(([^)]+)\)/;

              var matches = regExp.exec(uri);

              var newEntityId = matches[1];

              associateEntityToSolution(newEntityId,entityUniqueName);

          } else {

              window.parent.opener.Xrm.Utility.alertDialog(this.statusText);

          }

      }

  };

  req.send(JSON.stringify(param));

}

我在代码中缺少什么吗?还有其他解决方案可以使用javascript完成工作吗?


三国纷争
浏览 153回答 2
2回答

慕桂英546537

网址:POST [Your Org]/api/data/v9.0/AddSolutionComponent身体:{    "ComponentId" : "YourComponentGuid",    "ComponentType" : "YourComponentType",     "SolutionUniqueName" : "YourSolutionUniqueName",    "AddRequiredComponents" : "false", //false or true    "DoNotIncludeSubcomponents" : "true" //false or true}可以通过执行GET请求来检索ComponentId [Your Org]/api/data/v9.0/EntityDefinitions(LogicalName='YourEntityLogicalName')?$select=MetadataId
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript