收集 Aspose 动态幻灯片生成 CRM 2011 数据的空值



我正在使用Aspose在CRM Dynamics 2011 Microsoft幻灯片中生成动态内容。即使代码中的逻辑似乎是正确的并且不应产生 null 或空值,数据也没有正确填充多个字段和关系,并且我已经确认数据库中确实有字段的数据(数据确实正确填充了某些字段和关系)。 所有这些问题都发生在Powerpoint本身开始生成之前,因此实际上这些问题可能不是"Aspose"问题,它们可能只是异步检索数据的Web服务/CRM问题。

幻灯片工作流程:

1) HTML Web 资源包含一个用于下载 PowerPoint 报告的
Silverlight 按钮2) 在按钮上单击Silverlight应用程序 通过Web服务请求
异步收集CRM中的项目实体所需的所有数据3)数据被编译成一个项目类,然后传递给ReportGenerator服务,并使用这些数据来填充PowerPoint的各个部分(这是我们使用自定义Aspose内容的部分)
4) Aspose 功能遍历每个指定的幻灯片,并在需要时解析它们,并添加数据。5)Powerpoint完成并向用户吐出并填充数据。

这是我在获取数据填充时遇到麻烦的两个示例。 项目。下面的 Pwins 值最终为 null,这告诉我 lambda 表达式没有正确执行,它在方法结束时仍然是 null,这告诉我突出显示的行甚至根本没有执行。

示例 1:

    /// <summary>
    /// Retrieves and stores information required for P(win) report, and then tries to send a web service request.
    /// </summary>
    /// <param name="service"></param>
    private void LoadPwin(ReportServiceClient service)
    {
        string filter = string.Format("?$filter=sfa_Project/Id eq guid'{0}'", GetProjectId());
        string url = GetEntitySetAddress("sfa_pwin_competitor") + filter;
        WebClient client = new WebClient();
        client.DownloadStringCompleted += (sender, args) =>
        {
            if (args.Error == null)
            {
                StringReader stream = new StringReader(args.Result);
                XmlReader reader = XmlReader.Create(stream);
                List<PWin> pwins = new List<PWin>();
                List<Dictionary<string, string>> dictionaries = LoadEntitiesFromXml(reader);
                foreach (Dictionary<string, string> dictionary in dictionaries)
                {
                    PWin pwin = new PWin();
                    pwin.CompanyName = ParseDictionaryValue(dictionary["sfa_competitor"]);
                    pwin.IsBoeing = (ParseDictionaryValue(dictionary["sfa_is_boeing"]) == "true");
                    pwin.IsDomestic = (ParseDictionaryValue(dictionary["sfa_domestic_or_international"]) == "true");
                    pwin.AffordabilityWeight = ParseDictionaryValueToNumber(dictionary["sfa_affordability_weight"]);
                    pwin.AffordabilityScore = ParseDictionaryValueToNumber(dictionary["sfa_affordability_score"]);
                    pwin.CustomerRelationshipWeight = ParseDictionaryValueToNumber(dictionary["sfa_customer_relationship_weight"]);
                    pwin.CustomerRelationshipScore = ParseDictionaryValueToNumber(dictionary["sfa_customer_relationship_score"]);
                    pwin.CustomerAdvantageWeight = ParseDictionaryValueToNumber(dictionary["sfa_customer_advantage_weight"]);
                    pwin.CustomerAdvantageScore = ParseDictionaryValueToNumber(dictionary["sfa_customer_advantage_score"]);
                    pwin.CompetitionWeight = ParseDictionaryValueToNumber(dictionary["sfa_competition_weight"]);
                    pwin.CompetitionScore = ParseDictionaryValueToNumber(dictionary["sfa_competition_score"]);
                    pwin.CPOBCWeight = ParseDictionaryValueToNumber(dictionary["sfa_cpobc_weight"]);
                    pwin.CPOBCScore = ParseDictionaryValueToNumber(dictionary["sfa_cpobc_score"]);
                    pwin.CompanyResourcesWeight = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_weight"]);
                    pwin.CompanyResourcesScore = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_score"]);
                    pwin.CompanyResourcesInvestmentWeight = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_investment_weight"]);
                    pwin.CompanyResourcesInvestmentScore = ParseDictionaryValueToNumber(dictionary["sfa_company_resources_investment_score"]);
                    pwin.ProgramBackgroundWeight = ParseDictionaryValueToNumber(dictionary["sfa_program_background_weight"]);
                    pwin.ProgramBackgroundScore = ParseDictionaryValueToNumber(dictionary["sfa_program_background_score"]);
                    pwin.ContinuityOfEffortWeight = ParseDictionaryValueToNumber(dictionary["sfa_continuity_of_effort_weight"]);
                    pwin.ContinuityOfEffortScore = ParseDictionaryValueToNumber(dictionary["sfa_continuity_of_effort_score"]);
                    pwin.ExecutionWeight = ParseDictionaryValueToNumber(dictionary["sfa_execution_weight"]);
                    pwin.ExecutionScore = ParseDictionaryValueToNumber(dictionary["sfa_execution_score"]);
                    pwin.TechnicalSolutionWeight = ParseDictionaryValueToNumber(dictionary["sfa_technical_solution_weight"]);
                    pwin.TechnicalSolutionScore = ParseDictionaryValueToNumber(dictionary["sfa_technical_solution_score"]);
                    pwin.StrategyToWinWeight = ParseDictionaryValueToNumber(dictionary["sfa_strategy_to_win_weight"]);
                    pwin.StrategyToWinScore = ParseDictionaryValueToNumber(dictionary["sfa_strategy_to_win_score"]);
                    pwin.ManagementStrengthWeight = ParseDictionaryValueToNumber(dictionary["sfa_management_strength_weight"]);
                    pwin.ManagementStrengthScore = ParseDictionaryValueToNumber(dictionary["sfa_management_strength_score"]);
                    pwin.CustomerPercievedCommitmentWeight = ParseDictionaryValueToNumber(dictionary["sfa_customers_percieved_commitment_weight"]);
                    pwin.CustomerPercievedCommitmentScore = ParseDictionaryValueToNumber(dictionary["sfa_customers_percieved_commitment_score"]);
                    pwin.PastPerformanceWeight = ParseDictionaryValueToNumber(dictionary["sfa_past_performance_weight"]);
                    pwin.PastPerformanceScore = ParseDictionaryValueToNumber(dictionary["sfa_past_performance_score"]);
                    pwin.RawPWin = ParseDictionaryValueToDecimal(dictionary["sfa_pwin_score"]);
                    pwin.RelativePWin = ParseDictionaryValueToDecimal(dictionary["sfa_relative_pwin_score"]);
                    pwins.Add(pwin);
                }
                project.PWins = new ObservableCollection<PWin>(pwins);
                PwinReady = true;
                reader.Close();
                TrySendRequest(service);
            }
        };
        client.DownloadStringAsync(new Uri(url));
    }

示例 2 项目。下面的团队成员值最终为空:

    /// <summary>
    /// Retrieves and stores information required for Capture Team Roster report, and then tries to send a web service request.
    /// </summary>
    /// <param name="service"></param>
    private void LoadCaptureTeamRoster(ReportServiceClient service)
    {
        string filter = string.Format("?$select=sfa_name,sfa_Role&$filter=sfa_Project/Id eq guid'{0}'", GetProjectId());
        string url = GetEntitySetAddress("sfa_team_roster") + filter;
        WebClient client = new WebClient();
        client.DownloadStringCompleted += (sender, args) =>
        {
            if (args.Error == null)
            {
                StringReader stream = new StringReader(args.Result);
                XmlReader reader = XmlReader.Create(stream);
                List<TeamMember> members = new List<TeamMember>();
                List<Dictionary<string, string>> dictionaries = LoadEntitiesFromXml(reader);
                foreach (Dictionary<string, string> dictionary in dictionaries)
                {
                    TeamMember member = new TeamMember();
                    member.Name = ParseDictionaryValue(dictionary["sfa_name"]);
                    member.Role = ParseDictionaryValue(dictionary["sfa_role"]);
                    members.Add(member);
                }
                project.TeamMembers = new ObservableCollection<TeamMember>(members);
                CaptureTeamRosterReady = true;
                reader.Close();
                TrySendRequest(service);
            }
        };
        client.DownloadStringAsync(new Uri(url));
    }

下面是另一个示例,它不是关系的问题,而是在 CRM 中的项目实体上填充的字段的问题,该字段在检索数据后显示为空。 CaptureTeamLeader和ProgramManager最终都是空字符串,但是ProjectName和ProjectNumber

填充没有问题
    private void LoadCampaignTitle(ReportServiceClient service)
    {
        project.ProjectName = GetAttributeValue("sfa_name");
        project.ProjectNumber = GetAttributeValue("sfa_project_number");
        project.CaptureTeamLeader = GetAttributeValue("sfa_capture_team_leader_emp");
        project.ProgramManager = GetAttributeValue("sfa_program_manager_emp");
        CampaignTitleReady = true;
        TrySendRequest(service);
    }

任何帮助将不胜感激。 提前感谢!

编辑:

这是请求的属性值方法:

    /// <summary>
    /// Gets the value of provided attribute from the current page's Xrm data. If for any reason the retrieval fails, returns an empty string.
    /// </summary>
    /// <param name="attributeName"></param>
    /// <returns></returns>
    private string GetAttributeValue(string attributeName)
    {
        // NOTE: This is the preferred way to retrieve data from the CRM. However for some unknown issue,
        // this always returns NULL. It will be replaced with directly calling .eval to the window object.
        // dynamic Xrm = (ScriptObject)HtmlPage.Window.GetProperty("window.parent.Xrm");
        try
        {
            return HtmlPage.Window.Invoke("getAttributeValue", attributeName).ToString();
        }
        catch (ArgumentNullException)
        {
            return string.Empty;
        }
        catch (ArgumentException)
        {
            return string.Empty;
        }
        catch (InvalidOperationException)
        {
            return string.Empty;
        }
    }

这个问题的解决方案是数字 1 下载字符串异步和我代码中的其他地方正在异步执行操作,因此调试器将我抛弃并显示为 null,而它们实际上只是稍后执行。 实际修复需要对托管 Web 服务的文件夹中的客户端.xml文件进行一些更改。

最新更新