【问题标题】:How to correctly create javascript webresource programmatically如何以编程方式正确创建 javascript webresource
【发布时间】:2012-08-29 10:36:52
【问题描述】:

我是 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);
                }

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

提前感谢您的帮助。

【问题讨论】:

  • 是的,您确实会在您添加到的解决方案中看到创建的网络资源。
  • 我现在不清楚 - 您是说您的 Web 资源 正在 正在创建中,但它在默认解决方案中并且您希望它在指定的解决方案中?还是代码根本无法创建任何东西(您怀疑)?
  • @Greg,你猜对了。正在创建 Web 资源,它位于默认解决方案中。我还成功地将其添加到适当的解决方案中(提示:- 使用解决方案的唯一名称)。现在我的要求不同了。我必须以编程方式检测预定义解决方案的存在,如果不存在则创建它,并将 javascript Web 资源添加到该解决方案中。如果预定义的解决方案已经存在,那么我必须使用这个 js web 资源更新该解决方案,如果它不存在则创建 js web 资源,或者如果它已经存在则更新它。有什么指导吗?

标签: javascript dynamics-crm-2011 webresource


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2011-12-04
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2013-11-15
    • 2013-12-28
    • 2011-02-10
    • 2011-04-02
    • 2012-02-26
    相关资源
    最近更新 更多