2

我是 crm 新手,所以请原谅我的误解或不幸。

我正在尝试使用这样的 OrganizationServiceproxy 以编程方式创建 web 资源(准确地说是 javascript 或 jscript)早期绑定

          var context = new OrganizationServiceContext(service);

          var resource = (from wr in context.CreateQuery<WebResource>()
                          where wr.Name == name && wr.ComponentState.Value == 0
                          select wr).FirstOrDefault();

                if (resource == null)
                {
                  WebResource javascriptWebResource = new WebResource()
                        {
                            Name = name,
                            Description = name,
                            LogicalName = name,
                            DisplayName = value,
                            Content = Convert.ToBase64String(fileBytes),
                            WebResourceType = new OptionSetValue(3)

                        };
                    //context.AddObject(javascriptWebResource);
                    //context.SaveChanges();
                     service.Create(javascriptWebResource);
                }
                else
                {
                 //update the webresource
                 }

我的问题是 - 我是否需要设置比当前设置更多的实体元数据才能成功创建 Web 资源?

创建代码没有引发任何错误,但是我在指定解决方案的 crm 服务器上找不到我新创建的 javascript webresource。我猜想它是在将网络资源添加到默认解决方案中,因此我搜索了网络并在 sdk 中发现了一个示例,如下所示

  Guid theGuid = _serviceProxy.Create(wr);

                //If not the "Default Solution", create a SolutionComponent to assure it gets
                //associated with the ActiveSolution. Web Resources are automatically added
                //as SolutionComponents to the Default Solution.
                if (ActiveSolution.UniqueName != "Default")
                {
                    AddSolutionComponentRequest scRequest = new AddSolutionComponentRequest();
                    scRequest.ComponentType = (int)componenttype.WebResource;
                    scRequest.SolutionUniqueName = ActiveSolution.UniqueName;
                    scRequest.ComponentId = theGuid;
                    var response = (AddSolutionComponentResponse)_serviceProxy.Execute(scRequest);
                }

我的问题是 - 如果我检索 solutionuniquename 那么它会在适当的解决方案中创建 Web 资源并且我能够在 crm 服务器上看到 javascript Web 资源吗?

在此先感谢您的帮助。

4

1 回答 1

0

我知道这已经很晚了,但是如果 js 在 crm 系统中不存在,我会通过发送 createrequest 来解决它,或者如果 js 已经存在,则通过将 js 与特定解决方案相关联来解决它。顺便说一句,当您在 crm 中创建 js 时,它会同时添加到默认解决方案和您要更新的解决方案中。

于 2012-11-01T06:24:51.030 回答