Friday, March 4, 2016

Deactivate CRM Forms

Hi,

Deactivate CRM Forms.

Create an XML File and name it as SystemForm

XML FILE:

Pass formname and Objecttypecode in seperation of Comma

<?xml version="1.0" encoding="utf-8" ?>
<systemform>
  <form>account,1</form>
  <form>contact,2</form>
  <form>campaign,4400</form>
  <form>Campaign Activity,4402</form>
  <form>Contract,1010</form>
  <form>Contract Detail,1011</form>
  <form>Email,4202</form>
  <form>Appointment,4201</form>
  <form>Wizard,4201</form>
  <form>Email Server Profile,9605</form>
  <form>Fax,4204</form>
  <form>letter,4207</form>
  <form>Phone Call,4210</form>
  <form>Team,9</form>
  <form>Task,4212</form>
  <form>Sales Literature,1038</form>
  <form>Wizard,4202</form>
  <form>User,8</form>
  </systemform>


C# Code: 

var appSettings = ConfigurationSettings.AppSettings;
                XmlDocument systemform = new XmlDocument();
                systemform.Load(@"SystemForm.xml");
                int n;

                foreach (XmlNode node in systemform.DocumentElement.ChildNodes)
                {
                    string[] formnode = node.InnerText.Split(',');
                    bool isNumeric = int.TryParse(formnode[1], out n);
                    if (isNumeric)
                    {
                        QueryExpression deactivateForms = new QueryExpression(appSettings["EntityForms"]);
                        deactivateForms.ColumnSet = new ColumnSet(true);
                        deactivateForms.Criteria.AddCondition(new ConditionExpression(appSettings["FormName"], ConditionOperator.Equal, formnode[0].ToString()));
                        deactivateForms.Criteria.AddCondition(new ConditionExpression(appSettings["FormAttribute"], ConditionOperator.Equal, Convert.ToInt32(formnode[1].ToString()))); // Entity Object type code               
                        EntityCollection getDeactivatedfroms = orgService.RetrieveMultiple(deactivateForms);
                        foreach (Entity finaldeactivation in getDeactivatedfroms.Entities)
                        {
                            Entity newentity = new Entity(appSettings["EntityForms"]);
                            newentity[appSettings["FormAttribute"]] = finaldeactivation.Attributes[appSettings["FormAttribute"]];
                            newentity[appSettings["FormActivationState"]] = new OptionSetValue(Int32.Parse(appSettings["FormInActive"]));
                            newentity[appSettings["FormId"]] = finaldeactivation.Attributes[appSettings["FormId"]];
                            orgService.Update(newentity);
                        }
                    }
                    else
                    {
                        MessageBox.Show(formnode[1] + "is not Valid For Form Deactivation");

                    }

No comments:

Post a Comment

How to Run Microsoft Flow for Every one Month

Introduction: In this Blog we will see how to Run Microsoft Flow for Every one Month. Implementation Steps:   1. Navigate to  https://make.p...