Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

Create Contacs+Accounts and link them. From XML to Visual Studio to CRM

$
0
0

Hello everyone. Im fairly new to programming and everything around it and I cant break a "wall" to continue. Code so far:

xml: 

<contacts>
    <contact>
        <firstname>f1</firstname>
        <lastname>l1</lastname>
        <email>f1@email.com</email>
  <customer type="Lookup" entityType="account" searchField="name" allowCreate="true">
   <name>company1</name>
   <street>street1</street>
   <city>city1</city>
  </customer>
    </contact>
    <contact>
        <firstname>f2</firstname>
        <lastname>l2</lastname>
        <email>f2@email.com</email>
  <customer type="Lookup" entityType="account" searchField="name" allowCreate="false">
   <name>company2</name>
  </customer>
    </contact>
</contacts>

note: company 2 exists in crm already.

namespace createContact
{
    class Program
    {
        static void Main(string[] args)
        {
            CrmServiceClient crmConn = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CRM"].ConnectionString);
            IOrganizationService crmService = crmConn.OrganizationServiceProxy;
            Entity con = new Entity("contact");
            string[] info = new string[] { "firstname", "lastname", "emailaddress1" };
            int i = 0;
            using (XmlReader reader = XmlReader.Create(@"path"))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement())
                    {
                        switch (reader.Name.ToString())
                        {
                            case "firstname":
                                con[info[i]] = reader.ReadString();
                                i++;
                                break;
                            case "lastname":
                                con[info[i]] = reader.ReadString();
                                i++;
                                break;
                            case "email":
                                con[info[i]] = reader.ReadString();
                                i = 0;
                                crmService.Create(con);
                                break;
                        }
                    }
                }
            }
        }
    }
}
so far my Code only creates the Contacs. I did extend it already but it was more mess than a success.
My idea was to get to the type "Lookup" somehow and create an account from the Information in the child nodes. Then link the accounts to the contacs. (company2 exists already. I just Need to link that to the second contact.
Any Ideas what I Need to look up to do this?

Viewing all articles
Browse latest Browse all 46379

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>