Exemplo n.º 1
0
        private void BtnActivateFormulas_Click(object sender, EventArgs e)
        {
            var fetchXml = string.Empty;

            if (string.IsNullOrEmpty(txtInput.Text))
            {
                fetchXml = CrmHelper.GetFormulaFetchForMigrationEntities();
            }
            else
            {
                fetchXml = txtInput.Text;
            }

            var result = CrmConnManager.LService.RetrieveMultiple(new FetchExpression(fetchXml)).Entities;

            txtLog.AppendText($"Number of active formulas: {result.Count}");

            int count = 0;

            foreach (var en in result)
            {
                if (count++ % 50 == 0)
                {
                    txtLog.AppendText($"Activated formulas count: {count}");
                }

                var id = en.Id;

                var entityName = en.GetAttributeValue <string>("north52_sourceentityname");
                var name       = en.GetAttributeValue <string>("north52_name");

                try
                {
                    CrmHelper.ActivateRecord("north52_formula", id, CrmConnManager.RService);
                }
                catch (Exception ex)
                {
                    txtLog.AppendText($"**** Exception while activating formula: {name} {Environment.NewLine}");
                    txtLog.AppendText($"**** Message: {ex.Message} {Environment.NewLine}");
                }
            }
        }